hdu 4282 A very hard mathematic problem

    由于k的范围是0-2^31,而且x,y,z都是正整数,由题易知道2<=z<31,1<=x<y;所以直接枚举就好了!!!

 

#include<iostream>

#include<stdio.h>

#include<algorithm>

#include<iomanip>

#include<cmath>

#include<stdlib.h>

#include<cstring>

#include<vector>

#define ll __int64

#define pi acos(-1.0)

#define MAX 50000

using namespace std;

ll pows(ll a,ll b)

{

    ll ans=1;

    while(b){

        if(b&1) ans*=a;

        b>>=1;

        a*=a;

    }

    return ans;

}

int main(){

    int n,m,k;

    ll z,x,y,u,v;

    while (scanf("%d",&n)&&n){

        m = 0;

        k = (int)(sqrt(n*1.0)+1e-8);

        if (k*k == n) m = (k-1)/2;

        for (z=3;z<31;z++){

            for(x=1;;x++){

                u = pows(x,z);

                if(u>=n/2) break;

                for(y=x+1;;y++){

                    v = pows(y,z);

                    if (u+v+x*y*z==n){

                        m++;

                        break;

                    }

                    else if (u+v+x*y*z>n) break;

                }

            }

        }

        printf("%d\n",m);

    }

    return 0;

}
View Code

 

 

 

你可能感兴趣的:(Math)