PNUMBER

Đề bài

Đáp án

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
#include<math.h>
using namespace std;

int main(){
bool arr[1000001];
int a,b;
cin>>a>>b;
if(a<2) a=2;
for(int i=1;i<=b;i++){
arr[i] = true;
}
int sqr = sqrt(b);
for(int i=2;i<=sqr;i++){
if(arr[i]) {
for(int j=i*i; j<=b;j+=i){
arr[j] = false;
}
}
}
for(int i=a;i<=b;i++){
if(arr[i]){
cout<<i<<endl;
}
}
return 0;
}