blob: d19b4548b83521d81d6e49e5345f9c93d8e29119 (
plain) (
blame)
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
|
#include <algorithm>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
string line;
int s1 = 0, s2 = 0;
while (getline(cin, line)) {
// slurp it for part 2
istringstream is{line};
vector<int> v{istream_iterator<int>(is), {}};
auto [min, max] = minmax_element(begin(v), end(v));
s1 += *max - *min;
for (int a : v)
for (int b : v)
if (a > b && a % b == 0)
s2 += a / b;
}
cout << s1 << endl << s2 << endl;
return 0;
}
|