-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprimality_testing.cpp
More file actions
53 lines (50 loc) · 870 Bytes
/
Copy pathprimality_testing.cpp
File metadata and controls
53 lines (50 loc) · 870 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
#include <iostream>
#include <math.h>
#include <cstdio>
using namespace std;
int prime(int i)
{
long int f;
double r;
if (i == 1)
return 0;
else if (i < 4)
return 1;
else if (i%2 == 0)
return 0;
else if (i < 9)
return 1;
else if (i%3 == 0)
return 0;
else
{
r = sqrt(i);
f = 5;
while (f <= r)
{
if (i % f == 0)
return 0;
else if (i %(f+2) == 0)
return 0;
f += 6;
}
}
return 1;
}
int main()
{
int t;
int a,b,j;
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&a,&b);
for(j = a;j <= b;j++)
if (prime(j) == 1)
{
printf("%d",j);
cout<<endl;
}
}
return 0;
}