当我将限制从 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;
}
}
}
最佳答案
关于c++ - 当除数之和不大于数字时,程序将不接受大于 10000 的限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55320886/