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