题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4282
#include <iostream>
#include <cstdio>
#include <cmath>
#define LL __int64
using namespace std;
LL pow1(LL x,int z)
{
LL temp = x;
for(int i=2;i<=z;i++)
x *= temp;
return x;
}
int main()
{
//freopen("sum.in","r",stdin);
double n;
while(cin>>n,n)
{
int ans = 0;
int temp = sqrt(n);//C++有类型要求
if(temp*temp==n)
ans += (temp-1)>>1;//k==2时,为完全平方数公式,排除4包含4以下的
for(int z=3;z<31;z++)
{
for(LL x=1;;x++)
{
LL u = pow1(x,z);
if(u>=n/2)
break;
for(LL y=x+1;;y++)
{
LL v = pow1(y,z);
if(u+v+z*x*y>n)
break;
else if(u+v+z*x*y==n)
{
ans++;
break;
}
}
}
}
cout<<ans<<endl;
}
return 0;
}
本文提供了一个解决HDU在线评测平台4282号问题的C++实现方案,通过多重循环遍历可能的组合来计算满足条件的整数对数量,特别针对完全平方数进行了优化。

3232

被折叠的 条评论
为什么被折叠?



