<分区>
Possible Duplicate:
Project Euler Problem 12 - C++
我一直在研究欧拉问题,但遇到问题 12 时碰壁了。我阅读了一些大数的数学解决方案,但仍然没有得到正确的答案。这是我的代码:
#include <iostream>
using namespace std;
int divisorCount(const unsigned long long x)
{
int divizers = 0;
unsigned long long i = 1;
while(i <= x/i)
{
if(x % i == 0)
{
divizers++;
}
i++;
}
return divizers;
}
int main()
{
bool test;
unsigned long long total = 0, spread = 1;
int divisors = 1;
while(divisors < 501)
{
total+=spread;
divisors = divisorCount(total);
spread++;
if(divisors > 501)
cout << total << " " << spread << " " << divisors << endl;
}
cout << total << " is divisible by 500+ numbers" << endl;
system("pause");
return 0;
}
有什么建议吗?