-
Notifications
You must be signed in to change notification settings - Fork 0
/
prime.c
114 lines (60 loc) · 1002 Bytes
/
prime.c
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <stdio.h>
#define MAX_PRIME 32000
int primes[MAX_PRIME], req_prime[MAX_PRIME];
int total_prime=0;
void set_to_one()
{
for(int i=0;i<MAX_PRIME;i++)
primes[i]=1;
}
void preprocess()
{
primes[0]=primes[1]=0;
for(int i=2;i<MAX_PRIME;i++)
{
if(primes[i])
{
req_prime[total_prime++]=i;
for(int j=i+i;j<MAX_PRIME;j+=i)
{
primes[j]=0;
}
}
}
}
void check_prime(int n)
{
int count=0;
for(int i=0;i<total_prime;i++)
{
if(n%req_prime[i]==0 && n!=req_prime[i])
count++;
if(req_prime[i]>=n)
break;
}
if(count==0 && n!=1)
printf("%d\n",n);
}
void solve_problem(int arr[],int size)
{
for(int i=0;i<size;i++)
{
check_prime(arr[i]);
}
}
int main()
{
int test,a,b;
scanf("%d",&test);
set_to_one();
preprocess();
while(test--)
{
scanf("%d%d",&a,&b);
int arr[b-a+1];
for(int i=a;i<=b;i++)
arr[i-a]=i;
solve_problem(arr,b-a+1);
}
return 0;
}