我是小白,试了好多次我不会有大佬告诉我结果吗?
publicclasstest{
publicstaticvoidmain(String[]args)throwsIOException{
BufferedReaderbuf=newBufferedReader(new
InputStreamReader(System.in));
Stringstr=buf.readLine();
intx=Integer.parseInt(str);
if(x>=2){
intflag=x-1;
for(inti=2;i<=x;i++){
for(intj=2;j<=Math.sqrt(i);j++){
if(i%j==0){flag--;break;}
}
}
System.out.println(flag);
}
else{System.out.println(0);}
}
}
输入:1 输出:
输入:2 输出:
输入:20 输出:
输入:10000 输出: