hdu 4282A very hard mathematic problem(枚举+二分)
发布时间: 2013-10-30 12:56:21 作者: rapoo
hdu 4282A very hard mathematic problem(枚举+二分)
95360
110 Hint9 = 1^2 + 2^2 + 1 * 2 * 253 = 2^3 + 3^3 + 2 * 3 * 3
#include<iostream>#include<cstring>#include<cmath>#include<string>using namespace std;long long pow1(long long a,long long p){ long long s=1; while(p) { if(p&1) s*=a; a*=a; p>>=1; } return s;}int main(){ long long k; long long x,y,z; long long res,flag; while(cin>>k&&k) { res=0; for(z=2;z<=30;z++) //枚举z { long long tmp=pow(k/2.0,1.0/z); long long tmp1=pow(k*1.0,1.0/z); for(x=1;x<=tmp;x++) //枚举x { flag=0; long long l,r; l=x+1,r=tmp1; while(l<=r) //二分y { y=(l+r)>>1; long long s=pow1(x,z)+pow1(y,z)+x*y*z; if(s>k) r=y-1; else if(s<k) l=y+1; else { flag=1; break; } } if(flag) {res++;} } } cout<<res<<endl; } return 0;}/*625*///187MS