-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy path10394.cpp
More file actions
executable file
·45 lines (40 loc) · 836 Bytes
/
10394.cpp
File metadata and controls
executable file
·45 lines (40 loc) · 836 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
/* Problem: Twin Primes UVa 10394
Programmer: Md. Mahmud Ahsan
Description: Prime Number
Compiled: Visual C++ 7.0
Date: 13-08-05
*/
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define max 20000000
char seive[max];
int prime[100002];
//modified seive of eratosthenes
void genSeive(){
int i, j, sq;
seive[0] =seive[1] = 1;
sq = sqrt( (double) max);
for (i = 2; i <= sq; ++i){
if (!seive[i]){
for (j = i * i; j < max; j+=i)
seive[j] = 1;
}
}
//for twin prime modification
j = 0;
for (i = 2; i < max; ++i){
if (!seive[i] && !seive[i + 2])
prime[++j] = i;
if (j == 100001) break;
}
}
int main(){
genSeive();
int n;
while (cin >> n){
cout << "(" << prime[n] << ", " << prime[n] + 2 << ")" << endl;
}
return 0;
}