[英]Why do negative numbers in variables have a larger limit than a positive number (signed variables)?
[英]Determining factors of numbers when sum of divisors are not larger than the number, program will not accept a limit larger than 10000
当我将限制从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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.