blob: ed02c9ba17d7e1d9386be1d4a9ea06506946b0a4 (
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
53
|
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
tuple<long, long>
read_file(string_view filename)
{
fstream input{ filename };
vector<long> values;
for ( string word; input >> word; ) {
long value{};
if ( stringstream(word) >> value ) {
values.push_back(value);
}
}
return { values.at(0), values.at(1) };
}
long
triangle_num(long row, long col)
{
const auto side = row + col - 1;
return (side * (side + 1)) / 2 - row;
}
long
powmod(long base, long pow, long mod)
{
long result = 0;
for ( result = 1; pow != 0; pow /= 2 ) {
if ( pow % 2 == 1 ) {
result = (result * base) % mod;
}
base = (base * base) % mod;
}
return result;
}
void
part1(long row, long col)
{
cout << (powmod(252533, triangle_num(row, col), 33554393) * 20151125) % 33554393 << endl;
}
int
main()
{
const auto [row, col] = read_file("data/day25.txt");
part1(row, col);
}
|