Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include<iostream>
- using namespace std;
- int a[1000007];
- int b[1000007];
- int main(){
- //building of sieve
- a[0] = 0;
- a[1] = 0;
- //1000007 for just sake of simplicity
- for(int i = 2; i < 1000007; i++){
- a[i] = 1;
- // cout<<a[i]<<endl;
- }
- // cout<<a[1]<<a[0]<<a[100]<<endl;
- for(int i = 2; i * i <1000007; i++){
- if(a[i] == 1){
- for(int j = i * i; j < 1000007; j +=i ){
- a[j] = 0;
- }
- }
- }
- //storing of prime no.s into the aux array b for O(1) access
- int count = 0;
- for(int i = 0; i < 1000007; i++)
- {
- if(a[i] == 1){
- b[count++] = i;
- }
- }
- int t;
- cin>>t;
- while(t--){
- int n;
- cin>>n;
- cout<<b[n-1]<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment