-
Notifications
You must be signed in to change notification settings - Fork 0
/
day 64
33 lines (28 loc) · 735 Bytes
/
day 64
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
#include <iostream>
int main()
{
// enough primes for this problem
const unsigned int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 57 };
unsigned int tests;
std::cin >> tests;
while (tests--)
{
unsigned long long limit;
std::cin >> limit;
// multiply until we hit our limit
unsigned long long bestPos = 1;
for (auto p : primes)
{
// continue until bestPos reaches or exceeds our input value
//__int128 next = bestPos * p;
//if (next >= limit)
// break;
// same code as before but more portable:
if (bestPos >= (limit + p - 1) / p)
break;
bestPos *= p;
}
std::cout << bestPos << std::endl;
}
return 0;
}