TDKPRIME SPOJ SOLUTION

/* FINDING THE KTH PRIME SPOJ SOLUTION*/

#include<bits/stdc++.h>
using namespace std;
vector <bool> v(100000000,true);
int arr[8000000];
int main()
{
    long long int n = 100000000;
    long int i,j ;
    v[1] = false;
    v[0] = false;
    for(i=4;i<=n;i+=2)
     v[i]=false;
    for(i=3;i*i<=n;i+=2)
    {
        if(v[i])
        {
            for(j=i*i;j<=n;j=j+(2*i))
                v[j] = false;
        }
    }
         j=0;
         arr[0] = 2;
         for(i=3;i<=n;i+=2)
          {
            if(v[i])
            arr[++j]=i;
          }
         long long int t;
         cin>>t;
         while(t--)
          {
             long long int n;
             cin>>n;
              cout<<arr[n-1]<<"\n";
          }
            return 0;
      }

Comments

  1. Why have we made vector v(100000000,true);
    int arr[8000000]; global variables? Why didnt we use them inside the function?

    ReplyDelete
  2. BetMGM Casino App - JT Hub
    The BetMGM Casino 속초 출장안마 App offers a new bonus 목포 출장안마 in NJ and the option to 여수 출장안마 play for real money! 원주 출장안마 The bet $10 with a no deposit 여주 출장안마 bonus.

    ReplyDelete

Post a Comment

Popular posts from this blog

TDPRIMES SPOJ SOLUTION

Spoj CLOPPAIR Solution