HDU 4282 A very hard mathematic proble(暴力最適化)

2409 ワード

原題:http://acm.hdu.edu.cn/showproblem.php?pid=4282
A very hard mathematic proble m
Time Limit:2000/1000 MS(Java/Others)    メモリLimit:32768/32768 K(Java/Others)Total Submission(s):3871    Acceepted Submission(s):1133
Problem Description
Haoron is very goodt at soliving mathematic probles.Today he is working a problem like this: 
Find three positive integers X,Y and Z(X1)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 to Haoron.Now he wants to challing more:What’s the total number of different solution?
Surpringly、he is unable to solive this one.It seems that it's really a very hard mathematic proble.
Now,it’s your turn.
 
Input
The re 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 line for each test case.
 
Sample Input
 
   
9 53 6 0
 

Sample Output
 
   
1 1 0
题意:求出符合上面式子的个数

AC代码:

#include 
#include 
#define LL __int64
/*
author:YangSir
time:2014/5/9
*/
LL qpow(LL x,LL y) 
{ 
    LL temp=x,i; 
    for(i=2;i<=y;i++) 
		temp*=x; 
    return temp; 
} 

int main()
{
	LL n,m,x,y,z,k,s,num;
	while(~scanf("%I64d",&k)&&k)
	{
		num=0;
		s=sqrt(k);
		if(s*s==k)
		{
			num+=(s-1)/2;// z 2 ,        ,     s x、y   (x=k/2)//   xk)//       
						break;
					if(qpow(x,z)+qpow(y,z)+x*y*z==k)
					{
						num++;
						break;//    
					}
				}
			}
		}
		printf("%I64d
",num); } return 0; }