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 |
#include <iostream> #include <string> #include <vector> #include <math.h> #define SZ 20000001 using namespace std; int prime[SZ]; vector<int> v; struct twin{ int x; int y; }twinPrime[108001]; void primegen() { double p = sqrt(SZ); for(int i=3;i<p;i+=2) { if(prime[i]==0) { for(int j=i*i;j<SZ;j+=i) prime[j]=1; } } v.push_back(2); int cnt=0; for(int i=3;i<SZ;i+=2) { if(prime[i]==0) { v.push_back(i); int t=v.size(); if(v[t-1]-v[t-2]==2) { twinPrime[cnt].x = v[t-2]; twinPrime[cnt].y = v[t-1]; cnt++; } } } } int main() { primegen(); int size = v.size(); int n; while(cin>>n) { cout<<"("<<twinPrime[n-1].x<<", "<<twinPrime[n-1].y<<")\n"; } return 0; } |