Advertisement
NurUddinShohan

tdkprime

Sep 16th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. bool isprime[100000010];
  4. vector <int> prime;
  5. void seive()
  6. {
  7.  
  8.     for(int i = 2 ; i*i <= 100000000 ; i++)
  9.     {
  10.         if(isprime[i] == false)
  11.         {
  12.             for(int j = i*2; j <= 100000000 ; j += i )
  13.             {
  14.                 isprime[j] = true ;
  15.             }
  16.         }
  17.  
  18.     }
  19.     prime.push_back(2);
  20.     for(int i = 3 ; i <= 100000000 ; i += 2 )
  21.     {
  22.         if(isprime[i]== false)
  23.             prime.push_back(i);
  24.     }
  25. }
  26. int main()
  27. {
  28.     //freopen("/home/shohan/code/problem_solving/input.txt","r",stdin);
  29.     int n;
  30.     cin >> n;
  31.     seive();
  32.     int a[n];
  33.     for(int i = 0 ; i < n ; i++)
  34.         cin >> a[i];
  35.     seive();
  36.     //cout << prime.size()<< endl;
  37.     //cout << prime[5000000];
  38.     for(int i = 0 ; i < n ; i++)
  39.     {
  40.        // cout << a[i] << ' ';
  41.         cout << prime[a[i]-1] << endl;
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement