- 论坛徽章:
- 0
|
不知道perl运行要多久,我用C++,很快,大约1秒给出结果,和那位老兄结果一致。
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
long F(unsigned long n)
{
unsigned long sum = 0;
for(unsigned long i=1; i<=n; ++i)
sum += i;
return sum;
}
int CountYueShu(unsigned long sum)
{
unsigned long sq = sqrt(sum);
int count = 0;
for(unsigned long i=1; i<sq; ++i)
if(sum % i == 0)
count ++;
count = count * 2;
if(sum % sq == 0)
count ++;
return count;
}
int main(int argc, char *argv[])
{
unsigned long sum=0;
unsigned long n=1;
while(1)
{
sum = F(n);
if( CountYueShu(sum) >= 500 )
{
cout<< "The n is " <<n <<endl;
cout<< "The F(n) is " << sum <<endl;
break;
}
++n;
}
system("PAUSE");
return EXIT_SUCCESS;
} |
|