#include<stdio.h>
#include<math.h>
int main () {
int a,b,judge,n;
while(scanf("%d %d",&a,&b) != EOF) {
n = 0;
for(int i = a; i <= b; i++) {
judge = 1;
for(int j = 2 ; j <= sqrt(i);j++) {
if(i % j == 0) {
judge = 0;
break;
}
}
if(judge == 1) {
n++;
}
}
if(a == 1) //測資515
printf("%d\n",n-1);
else
printf("%d\n",n);
}
return 0;
}
n為計算a~b共有多少質數
judge判斷是否為質數 0代表否 1代表是
發現不是質數就馬上break 並且judge = 1
只要算該數到sqrt(s)即可