9 53 6 0
1 1 0Hint9 = 1^2 + 2^2 + 1 * 2 * 2 53 = 2^3 + 3^3 + 2 * 3 * 3
题解:把Z=2的情况特判一下,其他暴力枚举。
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
#define N 5005
#define ll long long
using namespace std;
ll k;
ll P(ll x,int n) {
    ll res=1;
    while(n) {
        if(n&1)res*=x;
        x*=x;
        n>>=1;
    }
    return res;
}
int main() {
   // freopen("test.in","r",stdin);
    while(~scanf("%I64d",&k)&&k) {
        int ans=0;
        ll kk=sqrt(k);
        if(kk*kk==k) {///z==2的情况
            ans+=(kk+1)/2-1;
        }
        for(int z=3; z<=31; z++) {
            for(int x=1;; x++) {
                ll xx=P((ll)x,z);
                if(xx>=k/2)break;
                for(int y=x+1;; y++) {
                    ll yy=P((ll)y,z);
                    if(yy+xx+(ll)x*y*z>k)break;
                    else if(yy+xx+(ll)x*y*z==k) {
                        ans++;
                        break;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}版权声明:本文为博主原创文章,未经博主允许不得转载。
hdu 4282 A very hard mathematic problem
原文:http://blog.csdn.net/acm_baihuzi/article/details/47431331