2014年西北工业大学机试第七题
程序员文章站
2022-05-15 14:08:36
...
#include<iostream>
#include<cmath>
using namespace std;
int n,m,book[10005]={0};
bool find(){
for(int i = 4; i <= m;i += 2){
book[i] = 1;//2的倍数先去掉
}
for(int i = 3;i <= m; i += 2){
for(int j = 2;j*i <= m;j++){
book[i*j] = 1;//奇数的倍数去掉
}
}
}
int main(){
cin>>n>>m;
find();
book[1] = 1;
for(int i = n;i <= m;i++){
if(book[i] == 0){
cout<<i<<endl;
}
}
return 0;
}