-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler69.cpp
53 lines (42 loc) · 919 Bytes
/
euler69.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
//DESCRIPTION: We exploit the observation that tot(n) can be obtained
// by multiplying n by (p - 1) / p for each prime p that divides n. This
// implies that we can multiply the smallest primes together until we exceed
// 1000000. The result will maximize the quotient.
#include <iostream>
#include <time.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <algorithm>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
bitset<10000010> pf;
vi primes;
void sieve(ll n) {
pf.set();
pf[0] = pf[1] = false;
for (ll i = 2; i <= n; i++) {
if (pf[i]) {
for (ll j = i * i; j <= n; j += i) {
pf[j] = false;
}
primes.push_back((int)i);
}
}
}
int main()
{
sieve(1000000);
ll prod = 1;
for (int i = 0; i < primes.size(); i++) {
prod *= primes[i];
if (prod > 1000000) {
prod /= primes[i];
break;
}
}
cout << prod << endl;
cin.get();
return 0;
}