-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAMR11E.cpp
More file actions
46 lines (42 loc) · 1.13 KB
/
AMR11E.cpp
File metadata and controls
46 lines (42 loc) · 1.13 KB
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
//http://www.spoj.com/problems/AMR11E/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = (int)1e6 + 1;
bool prime[N];
vector<ll int>primes , lucky;
void sieve()
{
memset(prime , true , sizeof(prime));
for(int i = 2;i < N;i++)
{
if(prime[i]) for(ll int j = i + i;j < N;j += i) prime[j] = false;
}
for(int i = 2;i < N && primes.size() < 1001;i++) if(prime[i]) primes.push_back(i);
}
void check(int n)
{
int c = 0;
for(int i = 0;i < primes.size();i++)
{
if(n % primes[i] == 0) c++;
if(c == 3){ lucky.push_back(n);break;}
}
}
int main()
{
std::ios::sync_with_stdio(0);cin.tie(0);
sieve();
int x = 30;
while(lucky.size() <= 1000)
{
check(x++);
}
int T;cin >> T;
while(T--)
{
int n;cin >> n;
cout << lucky[n - 1] << endl;
}
}
//tags - math , number theory