forked from knakul853/spoj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prime_generator.cpp
59 lines (50 loc) · 1.04 KB
/
prime_generator.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
#include<bits/stdc++.h>
#define ll long long
#define size1 45000
#include<vector>
void setprime();
void printprime(int a,int b);
int p[size1]; //stores the all possible prime factor of given no
void setprime(){
int temp=sqrt(size1);
int k=0;
for(int i=2;i<=size1;i++){ //creating all prime factor
int x=sqrt(i);
int flag=0;
for(int j=2;j<=x;j++){
if((i%j)==0){
flag=1;
break;
}
}
if(flag==0){
p[k++]=i;
}
}
}
void printprime(int a,int b){ //seive making using prime factors
int f;
setprime();
for(int i=a;i<=b;i++){
f=0;
for(int j=0;p[j]<=sqrt(i);j++){
if((i%p[j])==0){
f=1;break;
}
}
if(f==0 &&i!=1){
printf("%d\n",i);
}
}
}
using namespace std;
int main() {
int n;
scanf("%d",&n);
while(n--){
int a,b,f;
scanf("%d %d",&a,&b);
printprime(a,b);
}
return 0;
}