#28226: CPP


11030067@mail.hpsh.tp.edu.tw (和平110級鄧雨珊)

學校 : 臺北市立和平高級中學
編號 : 163096
來源 : [61.64.210.174]
最後登入時間 :
2022-10-23 16:54:59
a121. 質數又來囉 | From: [203.72.60.240] | 發表日期 : 2021-11-19 14:33

#include <iostream>
#include <cmath>
using namespace std;

bool isPrime(int x){
if (x==1){
return false;
}
if (x==2){
return true;
}
if (x%2==0){
return false;
}
for (int i=3; i<=sqrt(x); i+=2){
if (x%i==0){
return false;
}
}
return true;
}
int main(){
int a, b;
while (cin >> a >> b){
int c=0;
for (int i=a; i<=b; i++){
if (isPrime(i)){
c++;
}
}
cout << c <<endl;
}
}
 
ZeroJudge Forum