-
Notifications
You must be signed in to change notification settings - Fork 1
/
TDKPRIME.cpp
59 lines (46 loc) · 1 KB
/
TDKPRIME.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
int main()
{
long long int t=0,n,a,b,j,l,k,e,me,len;
scanf("%lld",&n);
a=1;
b=100000000;
b=b+1;
vector<bool> arr(100000005,1);
vector<long long int > coll;
arr[0]=arr[1]=0;
long double c = (sqrt(b-1));
l=int(c);
l=l+1;
coll.push_back(2);
for(int i=3;i<l;i+=2)
{
if (arr[i]==1 && i%2!=0)
{ coll.push_back(i);
k=i;
j=i;
j=k*j;
while(j<b)
{
arr[j]=0;
j=i;
k=k+2;
j=k*j;
}}}
for(int i=l;i<b;i+=2)
{
if(arr[i]==1)
coll.push_back(i);
}
while(t<n)
{
scanf("%lld",&me);
printf("%lld\n",coll[me-1]);
t++;
}
system("pause");
return 0;
}