Monday, April 03, 2017

UVa 10394 solution (Twine Prime)



UVa 10394 solution 
( Twine Prime )


Link of Problem::
https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1335


SOLIUTION::


SOLIUTION LINK::http://paste.ubuntu.com/24305142/

#include<bits/stdc++.h>
using namespace std;
int mx = 20000007;
char mark[20000007];
void sieve()
{
 mark[0] = mark[1] = 1;           // 1 means not prime
 for(int i = 4; i<mx; i+=2) mark[i] = 1;
 for(int i = 3; i*i<mx; i+=2)
  if(mark[i]==0)                   // i is a prime number
   for(int j = i*i; j<mx; j+=i+i)
    mark[j] = 1;
}


int main()
{
    vector<int>a;
    vector<int>c;
    vector<int>d;
    long long int n;
 sieve();
 for(int l=0; l<=20000000; l++)
    {
        if(mark[l]==0)
        {
            a.push_back(l);
        }
    }
 for(int r=1;r<a.size();r++)
 {
     if((a[r])-a[r-1]==2)
     {
         c.push_back(a[r-1]);   // change
         d.push_back(a[r]);  // change
     }
 }

    while(cin>>n)
    {

        cout<<'('<<c[n-1]<<", "<<d[n-1]<<')'<<endl;
    }
    return 0;
}

No comments:

Post a Comment