HDU 4282 A very hard mathematic problem [枚举]

  求X^Z+Y^Z+XYZ=K有多少正整数解。

  对于Z=2时是完全平方数可以直接求解,Z=3~31时直接暴力枚举即可,对于所有的X^Y可以全部预处理出来,最多大概也就50000*31种组合。

  其实确定了X和Z后,Y可以二分求解的,但当Z>=3时Y能取的值加起来也没有多少。。所以枚举就OK了。

  

 1 #include <stdio.h>
 2 #include <math.h>
 3 #define MAXN 47000
 4 typedef long long LL;
 5 const LL INF=(1LL<<31);
 6 LL p[47000][31],k;
 7 void init(){
 8     for(int i=1;i<MAXN;i++){
 9         p[i][0]=1;
10         for(int j=1;j<31;j++){
11             p[i][j]=p[i][j-1]*i;
12             if(p[i][j]>INF)p[i][j]=INF;
13         }
14     }
15 }
16 LL cal(int x,int y,int z){
17     return p[x][z]+p[y][z]+(LL)x*y*z;
18 }
19 int main(){
20     //freopen("test.in","r",stdin);
21     init();
22     while(scanf("%I64d",&k),k){
23         int ans=0;
24         int kk=sqrt((double)k);
25         if(kk*kk==k)ans=(kk-1)/2;
26         for(int z=3;z<31;z++){
27             for(int x=1;cal(x,x+1,z)<=k;x++){
28                 for(int y=x+1;;y++){
29                     LL tmp=cal(x,y,z);
30                     if(tmp>k)break;
31                     if(tmp==k)ans++;
32                 }
33             }
34         }
35         printf("%d\n",ans);
36     }
37 
38     return 0;
39 }
posted @ 2012-09-14 10:43  Burn_E  阅读(178)  评论(0)    收藏  举报