a121.
質數又來囉
| From: [114.27.72.98] |
發表日期
:
2012-07-16 22:27
import java.util.Scanner;
public class a121{
public static void main(String [] argv){
Scanner abc = new Scanner(System.in);
while(abc.hasNext()){
int a = abc.nextInt();
int b = abc.nextInt();
int o = 0;
boolean i = true;
int d =(int) Math.sqrt(b);
for(long c = a;c <= b;c++){
if(c == 1)i=false;
if(c == 2)i=true;
if(c == 3)i=true;
if(c == 5)i=true;
if(c == 7)i=true;
if(c != 2 && c % 2==0)i=false;
if(c != 3 && c % 3==0)i=false;
if(c != 5 && c % 5==0)i=false;
if(c != 7 && c % 7==0)i=false;
for(int s = 3;s<=d;s= s+2){
if(c % s==0){
i = false;
break;
}
}if(i){
o++;
}
i = true;
}System.out.println(o);
}
}
}