当我将限制从100更改为1,000,000时,它不会打印出所有数字,它会以5位数字停止,不会再计算出更高的数字。为什么会这样?
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
const int limit = argc > 1 ? atoi(argv[1]) : 100;
const int badness = argc > 2 ? atoi(argv[2]) : 1;
for (int num = 2; num < limit; num++) {
int total = 1;
for (int factor = 2; factor * factor <= num; factor++) {
if (num % factor == 0) {
total += factor;
if (factor * factor != num) {
total += (num / factor);
}
}
}
if (abs(num - total) <= abs(badness)) {
cout << num << " " << flush;
}
}
}