Time limit : 10 sec | Memory limit : 64 M |
According to Goldbach’s conjecture, every evennumber can be expressed as a sum of two oddprimes. Which numbers can be expressed as thesum of two cubes?
For each test case, a line will contain a positive integer n which will be at most one million.For each test case, output two integers x and y such that x3 + y3 = n. If there are manysuch pairs of numbers, choose x to be as small as possible. If there are no such pairs, output“impossible”.
The last line will contain the integer 0, which should not be processed.
Sample Input
1 2 3 1000000 0
Sample Output
0 1 1 1 impossible 0 100
Solution:
#include <stdio.h>
#include <math.h>
int main()
{
int x, y, n;
while(1 == scanf("%d", &n))
{
if(0 == n)
return 0;
x = -600;
y = 600;
for(;x <= y;)
{
if ((int)(pow(x, 3) + pow(y, 3)) > n)
{
--y;
}
else if ((int)(pow(x, 3) + pow(y, 3)) < n)
{
++x;
}
else
{
printf("%d %d\n", x, y);
break;
}
}
if (x > y)
{
printf("impossible\n");
}
}
return 0;
}
注意:x和y並沒有指明是正數