#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int T,N;
long long n,d;
int a,b,x,y,tmp;
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&N);
if(N<3){
printf("IMPOSSIBLE\n");
continue;
}
if(N%2){
a=N/2;
printf("%d = %d + %d\n",N,a,a+1);
continue;
}
n=N;
while(n%2==0){
n/=2;
}
if(n==1){
printf("IMPOSSIBLE\n");
continue;
}
y=3;n=2*N;
d=sqrt(n*1.0)+5;
for(y;y<=d;y++){
if(n%y==0){
x=n/y;
if((x+y)%2){
goto AA;
}
}
}
AA:
if(x<y){
tmp=x;
x=y;
y=tmp;
}
b=(x+y-1)/2;
a=(x-y+1)/2;
printf("%d = %d",N,a);
for(int i=a+1;i<=b;i++){
printf(" + %d",i);
}
printf("\n");
}
return 0;
}Uvalive 6929 Sums
最新推荐文章于 2019-10-11 23:12:55 发布
本文深入探讨了一种用于分解特定数值的算法实现过程。通过输入整数N,该算法能够将其表示为两个整数之和,适用于N小于3的情况,并在N为偶数时进一步优化分解方式。对于奇数N,算法直接给出N的一半加一的分解;对于偶数N,通过求解特定条件下的整数y和x,最终得出分解结果。此过程不仅展示了算法的高效性,还涉及了数学中的平方根、除法和模运算等基本概念。
927

被折叠的 条评论
为什么被折叠?



