UVa 10394 - Twin Primes Solution

#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
vector<vector<int> > a;
bitset<20000000> pr;
int main(){
    pr[0]=pr[1]=1;
    ios::sync_with_stdio(0);
    for(int i=2;i<2e7;i++){
        if(!pr[i]){
            if(!pr[i-2])
                a.push_back({i-2,i});
            if(i<=4500)
                for(int j=i*i;j<2e7;j+=i)
                    pr[j]=1;
        }
    }
    int n;
    while(cin>>n){
        cout<<'('<<a[n-1][0]<<", "<<a[n-1][1]<<')'<<endl;
    }
}

Comments