我试图解决项目欧拉的问题5,但程序崩溃,我没有得到任何错误:C++控制台程序崩溃,并且没有任何错误
#include <stdio.h>
#include <iostream>
using namespace std;
/* Problem 5:
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
*/
int selle(int number) {
int c = 0;
for (int i = 0; i <= 20; i++)
if (number % i == 0)
c++;
return c;
}
int problem(int number) {
while (number > 0) {
if (selle(number) == 20)
return number;
number++;
}
return 404;
}
int main() {
long long number = 2;
cout << problem(number);
system("PAUSE");
return 0;
}
我认为这个问题是在“供”在第一个函数中循环,但我不知道它是什么。也试图设置功能很长很长时间它发生。 谢谢。
我想你应该使用根据欧几里得最大公约数(GCD)定义的最小公倍数(LCM)函数。 –
在Windows中,程序产生一个错误框“停止工作”。在过去,它曾经鼓励用户告诉比尔盖茨。显然,他为他创造了太多的工作,因为现在它说Windows正在检查一个解决方案(人工智能,耶!),然后改变让我调试或关闭程序。 –
法国gcc告诉我'例外flottant'! – jpo38