各位大大,我不知道我哪裡錯了,第518行一直測不過
package Basic;
public class A121 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int a = sc.nextInt();
int b = sc.nextInt();
int ans = 0;
if(a==b){
ans = 0;
}else{
for(int i=a;i<=b;i++){
if(isPrime(i))
ans++;
}
}
System.out.println(ans);
}
}
static boolean isPrime(int n) {
//check if n is a multiple of 2
if (n%2==0){
if(n==2)
return true;
else
return false;
}
else if(n==1){
return false;
}
//if not, then just check the odds
for(int i=3;i*i<=n;i+=2) {
if(n%i==0)
return false;
}
return true;
}
}