A very hard mathematic problem
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=4282
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.
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
TThere 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
题意
给你K,求X^Z+Y^Z+X*Y*Z=K有多少个解
题解:
枚举X,Z,二分Y
代码
#include<iostream>
#include<cstdio>
#include<cmath> using namespace std; int k,maxa; inline int f(int a,int b,int x)
{
return pow(x*1.0,b*1.0)+pow(a*1.0,b*1.0)+a*b*x-k;
} bool judge(int a,int b)
{
int L,R,M,t;
L=a+;R=maxa;
if(f(a,b,L)>||f(a,b,R)<) return false;
while(L<=R)
{
M=(L+R)>>;
t=f(a,b,M);
if(t==) return true;
else if(t>) R=M-;
else L=M+;
}
return false;
} int main()
{
int ans,a,b;
while(scanf("%d",&k)==&&k)
{
ans=;
for(b=;b<=;b++)
{
maxa=pow(k*1.0,1.0/b);
for(a=;a<=maxa;a++)
{
if(judge(a,b))
ans++;
}
}
printf("%d\n",ans);
}
return ;
}