楼上你的代码会很慢的...
以下是我从yzfy的论坛上复制来的代码,很快,但说实话,我没看懂...
//Author: maths_dxj
#include<cmath>
#include<cstdio>
#include <basetsd.h>
#include <cstdlib>
void FindPerfect(__int64 &n)
{
int s[8]={2,3,5,7,13,17,19,31};
__int64 PerfectNmber;
__int64 i,j,l;
for (i=0;i<8;i++)
{
l=(__int64)(pow(2,s[i])-1);
PerfectNmber=(l+1)/2*l;
if (PerfectNmber>n)return;
else
printf("%I64d\n",PerfectNmber);
}
return;
}
int main(void)
{
__int64 n;
while (scanf("%I64d",&n)!=EOF)
FindPerfect(n);
return 0;
}