forked from singhsanket143/CppCompetitiveRepository
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.cpp
More file actions
40 lines (38 loc) · 823 Bytes
/
hello.cpp
File metadata and controls
40 lines (38 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;
vector<bool> p(100000,false);
void prime_sieve(vector<bool> p, long long int n){
p[0]=p[1] = 0;
p[2] = 1;
for(int i=3; i<=n; i+=2){
p[i] = 1;
}
for(int i=3; i<=n; i+=2){
if(p[i]){
for(int j=i*i; j<=n; j+=2*i){
p[j] = 0;
}
}
}
}
int main() {
int N = 100000;
// int p[N] = {0};
prime_sieve(p,100000);
int t;
cin>>t;
int primes_req;
for(int i=1; i<=t; i++){
cin>>primes_req;
int primes_found=0;
for(long long int j=0; j<=100000; j++){
if(p[j]){
primes_found++;
}
if(primes_found==primes_req){
cout<<j<<endl;
break;
}
}
}
}