题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4282
解题思路:
题目大意:
给你一个式子 x^z + y^z + x*y*z = k,k 为给定的某个 int 范围内的数字,求共有多少组关于 x,y,z 的解。(0< x < y,z > 1)
X^Z + Y^Z + XYZ = K K<2^31
当z=2时,式子转化为 tmp^2=x^2+y^2+2*x*y=(x+y)^2, x,y的范围 <2^16
当z>2时,x,y范围 <2^10=1024.暴力枚举即可。。。
AC代码:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
int main(){
int n;
while(scanf("%d",&n),n){
ll ans = 0;
int tmp = sqrt(n*1.0);
for(int i = 1; i <= tmp; i++){ //特判k==2
if(i*i == n){
ans = (i-1)/2;
break;
}
}
for(int z = 3; z <= 31; z++){
for(ll x = 1; x <= 1100; x++){//2^10=1024
for(ll y = x+1; y <= 1100; y++){
ll temp = pow(x,z) + pow(y,z) + x*y*z;
if(temp == n){
ans++;
break;
}
else if(temp > n)
break;
}
if(pow(x,z)>n)
break; //x^z>n则直接跳出
}
}
printf("%lld\n",ans);
}
return 0;
}