blob: 85e3539c79cb36788585081eb3b46ef28723dab9 (
plain)
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
|
#include <iostream>
#include <unordered_map>
using namespace std;
void
part1(int limit)
{
unordered_map<int, int> house;
for ( int i = 1; i < limit / 10; ++i ) {
for ( int j = i; j < limit / 10; j += i ) {
house[j] += i * 10;
}
}
for ( int i = 0;; ++i ) {
if ( house[i] >= limit ) {
cout << i << endl;
return;
}
}
}
void
part2(int limit)
{
unordered_map<int, int> house;
for ( int i = 1; i < limit / 10; ++i ) {
int visits = 0;
for ( int j = i; j < limit / 10; j += i ) {
if ( visits++ < 50 ) {
house[j] += i * 11;
}
}
}
for ( int i = 0;; ++i ) {
if ( house[i] >= limit ) {
cout << i << endl;
return;
}
}
}
int
main()
{
static const auto limit = 29000000;
part1(limit);
part2(limit);
}
|