-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_20b.cpp
49 lines (46 loc) · 1.09 KB
/
day_20b.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
#include <fstream>
#include <iostream>
#include <regex>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
std::unordered_map<int, int> n_visits;
int presents(const int n) {
int presents = 0;
int i = 1;
while(i * i <= n) {
if (n % i == 0) {
if (n_visits[i] < 50) {
presents += i * 11;
n_visits[i]++;
}
const int i2 = n/i;
if (i2 != i && n_visits[i2] < 50) {
presents += i2 * 11;
n_visits[i2]++;
}
}
i++;
}
// std::cout << n << ": " << presents << '\n';
return presents;
}
int main(int argc, char * argv[]) {
std::string input = "../input/day_20_input";
if (argc > 1) {
input = argv[1];
}
std::ifstream file(input);
std::string line;
std::getline(file, line);
const int min_presents = std::stoi(line);
int n = 0;
while (presents (n) < min_presents) {
n++;
}
std::cout << n << '\n';
return 0;
}