A very hard mathematic problem
Problem Description
Haoren is very good at solving mathematic problems. Today he is working a problem like this: 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.
Input
There are multiple test cases. For each case, there is only one integer K (0 < K < 2^31) in a line. K = 0 implies the end of input.
Output
Output the total number of solutions in a line for each test case.
Sample Input
9 53 6 0
Sample Output
1 1 0
Hint
9 = 1^2 + 2^2 + 1 * 2 * 2 53 = 2^3 + 3^3 + 2 * 3 * 3确定要y,z对x进行二分
#include<iostream>
#include<stdio.h>
using namespace std;
#define ll __int64
ll lmx(ll z,ll y,ll k)
{
ll i,sum=0,l,r,xx=1,mid;
l=1;r=y-1;
while(l<=r)
{
mid=(l+r)/2;
xx=1;
for(i=0;i<z;i++)
{
xx*=mid;
}
sum=xx+mid*z*y;
if(sum==k) return 1;
if(sum<k) l=mid+1;
else r=mid-1;
}
return 0;
}
int main()
{
ll n,i,y,z,head,rear,mid,cnt;
while(scanf("%I64d",&n)&&n)
{
cnt=0;
for(y=2;y*y<=n;y++)
{
for(z=2;;z++)
{
ll yy=1;
for(i=0;i<z;i++) yy*=y;
if(yy>n) break;
if(lmx(z,y,n-yy)) cnt++;
}
}
printf("%I64d\n",cnt);
}
return 0;
}
#include<stdio.h>
using namespace std;
#define ll __int64
ll lmx(ll z,ll y,ll k)
{
ll i,sum=0,l,r,xx=1,mid;
l=1;r=y-1;
while(l<=r)
{
mid=(l+r)/2;
xx=1;
for(i=0;i<z;i++)
{
xx*=mid;
}
sum=xx+mid*z*y;
if(sum==k) return 1;
if(sum<k) l=mid+1;
else r=mid-1;
}
return 0;
}
int main()
{
ll n,i,y,z,head,rear,mid,cnt;
while(scanf("%I64d",&n)&&n)
{
cnt=0;
for(y=2;y*y<=n;y++)
{
for(z=2;;z++)
{
ll yy=1;
for(i=0;i<z;i++) yy*=y;
if(yy>n) break;
if(lmx(z,y,n-yy)) cnt++;
}
}
printf("%I64d\n",cnt);
}
return 0;
}
为了明天所以选择坚定的执着今天。