3.1w+
社区成员
本题运用枚举,需要注意应用Math.sqrt(),如果直接j运行的范围写成<=i,则运行结果超时,而对于应用Math.sqrt()方法,在最后对count约数进行统计时,需要对其进行×2,因为sqrt开平方,左边一侧有的,右边一侧也有。
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
public static void main(String[] args) {
for(int i=6;;i++){
int count=0;
for(int j=1;j<=Math.sqrt(i);j++){
if(i%j==0){
count++;
}}
if(count*2==100){
System.out.println(i);
break;
}
}
}
}