确定数的因数 当除数之和不大于该数时,程序将不接受大于 10000 的限制
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;
}
}
}
看看这个 https://en.wikipedia.org/wiki/C_data_types
这可能是因为您使用的是 int。
尝试使用长整型或无符号长整型
相关文章:
- 为什么线程不接受此输入?
- C++程序不会从 Windows 控制台运行
- 程序不会执行函数 c++
- 为什么我的程序不能显示斐波那契级数?
- 函数不接受 X 参数,函数使用默认参数
- C++ boost::asio::ip::tcp::acceptor 有时不接受连接器?
- 为什么使用数组元素查找最大数字的程序不起作用?
- 程序不向函数返回值
- 英特尔 TBB 程序不会终止,可能会误用参考计数器
- C++ 程序不会因为内存而终止
- B不接受8作为输入的是什么?C++
- 为什么一个简单的程序不能立即启动
- C++数组输入不接受一定数量的整数
- 我的C++程序不接受菜单后的输入
- 确定数的因数 当除数之和不大于该数时,程序将不接受大于 10000 的限制
- 程序不接受任何输入.第一次输入后,它会自动关闭
- C++中的代码将不接受否并停止程序
- C++ - 使用 cin 循环运行 while 后,程序不会再次接受输入
- 我在我的程序中添加了一个void函数,它不接受任何参数,现在我的程序在运行时只返回一个空白终端
- cin不接受输入,程序立即关闭