该代码似乎适用于 10,但不适用于问题所要求的 20。 也许这个数字太大了,当它能被 20 整除时......
public static void main(String args[]) {
long c = 0;
while(true){
int x = 0;
c++;
for(int i = 1; i<=20; i++){
x += c%i;
}
if(x==0){
System.out.println(c);
break;
}
}
}
}
没有错误消息,它只是继续运行而没有“进程完成”
最佳答案
您基本上是在尝试找到 1-20 个数字的最小公倍数。其 LCM 为 2,32,792,560。该程序最终将完成,但速度会非常慢。
要测试的示例程序。
public static void main(String args[]) {
long c = 232792559;
while (true) {
int x = 0;
c++;
for (int i = 1; i <= 20; i++) {
x += c % i;
}
if (x == 0) {
System.out.println(c);
break;
}
}
}
输出为 232792560
关于java - 欧拉投影最小倍数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57277789/