Advertisement
Anik_Akash

1086. Cryptography [Times]

Aug 12th, 2020 (edited)
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. //thanks God For Every Thing!
  2. //contest link:
  3. #include<bits/stdc++.h>
  4. #define pi                      acose(-1)
  5.  
  6. typedef long long int           ll;
  7. typedef double                  dl;
  8. using namespace std;
  9. const int mx = 1e2+5;
  10. void seive();
  11. ll prime[170000];
  12. int main()
  13. {
  14.     ios_base::sync_with_stdio(false);
  15.     cin.tie(NULL);
  16.     cout.tie(NULL);
  17.  
  18.     ll  t, a, x;
  19.     scanf("%lld", &t);
  20.    seive();
  21.     for(a=0; a<t; a++)
  22.     {
  23.         scanf("%lld", &x);
  24.         printf("%lld\n", prime[x-1]);
  25.     }
  26.     return 0;
  27. }
  28. void seive()
  29. {
  30.     ll n, i, j;
  31.     n = 170000;
  32.     ll m=0;
  33.     prime[m++]=2; //prime initialize;
  34.  
  35.     bool vis[n]= {}; //making false value to check;
  36.     for(i=3; i<=n; i+=2) //checker;
  37.     {
  38.         if(vis[i]==false)
  39.         {
  40.             prime[m++]=i; //store prime
  41.             for(j=i*i; j<=n; j+=i+i) vis[j]=true; //cut off not prime;
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement