-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime1.cpp
More file actions
59 lines (57 loc) · 847 Bytes
/
Copy pathprime1.cpp
File metadata and controls
59 lines (57 loc) · 847 Bytes
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
#include<iostream>
using namespace std;
#define MAX 32000
int prime[MAX],reqd_prime[MAX];
int total_primes=0;
int setToOne()
{
int i;
for(i=0;i<MAX;i++)prime[i]=1;
return 0;
}
int findPrimes()
{
prime[0]=prime[1]=0;
int i,j;
for(i=2;i<MAX;i++){
if(prime[i]){
for(j=2*i;j<MAX;j+=i){
prime[j]=0;
}
reqd_prime[total_primes++]=i;
}
}
return 0;
}
bool checkPrimes(int n)
{
int i;
bool flag=true;
for(i=0;i<total_primes;i++){
if(n%reqd_prime[i]==0 && n!=reqd_prime[i]){
flag=false;
break;
}
}
if(flag&&n!=0&&n!=1)return true;
else return false;
}
int main()
{
setToOne();
findPrimes();
int i,t;
/*for(i=0;i<100;i++){
cout<<prime[i]<<" "<<reqd_prime[i]<<endl;
}
cout<<endl;*/
cin>>t;
while(t--){
int a,b;
cin>>a>>b;
for(i=a;i<=b;i++){
if(checkPrimes(i))cout<<i<<endl;
}
cout<<endl;
}
}