Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. int main(){
  6.     ios::sync_with_stdio(0); cin.tie(0);
  7.     int N=20000000;
  8.     vector<bool> prime(N+1,1);
  9.  
  10.     int last=2;
  11.     vector<pair<int,int>> twin;
  12.  
  13.     for(int p=3; p<=N; p+=2){
  14.         if(prime[p]){
  15.             if(p-last==2) twin.push_back({last,p});
  16.             last=p;
  17.             for(int i=2*p; i<=N; i+=p){
  18.                 prime[i]=0;
  19.             }
  20.         }
  21.     }
  22.  
  23.     int n;
  24.     while(cin>>n){
  25.         auto p=twin[n-1];
  26.         printf("(%d, %d)\n",p.first,p.second);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement