-
Notifications
You must be signed in to change notification settings - Fork 9
/
day_20a.cpp
41 lines (39 loc) · 905 Bytes
/
day_20a.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
#include <fstream>
#include <iostream>
#include <regex>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
int presents(const int n) {
int presents = 0;
int i = 1;
while(i * i <= n) {
if (n % i == 0) {
presents += i * 10;
const int i2 = n/i;
if (i2 != i) presents += i2 * 10;
}
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;
}