A very hard mathematic problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1455 Accepted Submission(s): 440
Find three positive integers X, Y and Z (X < Y, Z > 1) that holds
X^Z + Y^Z + XYZ = K
where K is another given integer.
Here the operator “^” means power, e.g., 2^3 = 2 * 2 * 2.
Finding a solution is quite easy to Haoren. Now he wants to challenge more: What’s the total number of different solutions?
Surprisingly, he is unable to solve this one. It seems that it’s really a very hard mathematic problem.
Now, it’s your turn.
For each case, there is only one integer K (0 < K < 2^31) in a line.
K = 0 implies the end of input.
#include<string.h>
#include<stdio.h>
#include<math.h>
long long y,z,k,sum,f,ok[1290];
long long fx(long long a,long long b,long long c)
{
long long i,aa=1,bb=1;
for (i=1;i<=c;i++)
{
aa=aa*a;//本來用pow,記得好像是計算實數會不會有精度誤差不用算了-
bb=bb*b;
}
return aa+bb+a*b*c;
}
void find(long long l,long long r)
{
long long m=(l+r)/2,key;
key=fx(m,y,z);
if (key==k) {if (m>0&&m<y) f=1; return ;}
if (l>=r) return;
if (key<k) find(m+1,r);
else find(l,m-1);
}
int main()
{
long long t,exp=0;
while (scanf("%lld",&k),k)
{
sum=0;
t=sqrt(k);
if (t*t==k)//z=2,直接開方,
{
if (t%2==1) sum=t/2;
else sum=t/2-1;
}
for (z=3;fx(1,2,z)-exp<=k;z++)
{
y=2;
while (fx(1,y,z)-exp<=k)//說起exp,是爲了調試程序用的看邊界條件,其實邊界開始就對的最後exp=0,可有可無
{
f=0;
find(1,y-1);
sum=sum+f;
++y;
}
}
printf("%lld\n",sum);
}
return 0;
}最後再去hdu用gcc跑了下15ms,再用c跑了下0ms,衝到第一了吼吼。