So easy(?)
2026-01-03 09:24:30
发布于:上海
8阅读
0回复
0点赞
#include<iostream>
using namespace std;
//判断素数函数
bool su(int a){
//第一个判断语句其实不用,因为给的范围是>1的
if(a==1){
return false;
}
else if(a==2||a==3||a==5||a==7||a==11||a==13||a==17||a==19||a==23||a==29||a==31){
return true;
}
else if(a%2!=0&&a%3!=0&&a%5!=0&&a%7!=0&&a%11!=0&&a%13!=0&&a%17!=0&&a%19!=0&&a%23!=0&&a%29!=0&&a%31!=0){
return true;
}
else{
return false;
}
}
int main(){
int A,B,count=0;
cin>>A>>B;
for(int i=A;i<=B;i++){
if(su(i)){
count++;
}
}
cout<<count;
}
有个样例是
in
2
1000
out
178
所以要判断到31才行
这里空空如也







有帮助,赞一个