-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_erasth_primes.cpp
63 lines (58 loc) · 1.01 KB
/
2_erasth_primes.cpp
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<iostream>
using namespace std;
int primes[3500],l=0;
bool isPrime(int i)
{
for(int j=0;j<l;j++)
{
if(i%primes[j]==0)
return false;
}
return true;
}
int main()
{
int i,k=2,temp;
bool a[32000];
for(i=0;i<32000;i++)
a[i]=true;
while(k*k<32000)
{
temp=1;
while(temp*k<32000)
{
a[temp*k]=false;
temp++;
}
primes[l++]=k;
while(a[k]==false)
{
k++;
}
}
primes[l++]=k;
while(k<32000)
{
if(a[k]==true)
primes[l++]=k;
k++;
}
/*for(i=0;i<50;i++)
cout<<primes[i]<<"\n";*/
//cout<<"\n"<<float(end-start)<<"\n\n\n";
int N,n,m;
cin>>N;
while(N--)
{
cin>>m>>n;
if(m==1)
m=2;
for(int r=m;r<=n;r++)
{
if(isPrime(r))
cout<<r<<"\n";
}
cout<<"\n";
}
return 0;
}