-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10394 - Twin Primes.cpp
More file actions
58 lines (47 loc) · 961 Bytes
/
10394 - Twin Primes.cpp
File metadata and controls
58 lines (47 loc) · 961 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
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<iostream>
#include<math.h>
using namespace std;
vector<int>prme;
bool prime[20000010];
void Prime_Sieve()
{
prime[1]=false;
int i,not_prime;
int n=sqrt(20000010);
for(i=3; i<=n; i++)
{
if(prime[i]==true)
{
for(not_prime=i*2; not_prime<=20000010; not_prime+=i)
{
prime[not_prime]=false;
}
}
}
int k;
for(k=2; k<=20000010; k++)
{
if(prime[k]==true&&prime[k+2]==true)
{
prme.push_back(k);
}
}
}
int main()
{
int number,c;
memset(prime,true,sizeof(prime));
Prime_Sieve();
while(scanf("%d",&number)!=EOF)
{
printf("(%d, %d)\n",prme[number],prme[number]+2);
prme.clear();
}
return 0;
}