-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMatrix
79 lines (66 loc) · 1.52 KB
/
Matrix
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
practice problems :
problem: https://codeforces.com/problemset/problem/514/E
solution: https://codeforces.com/contest/514/submission/183516372
problem: https://codeforces.com/problemset/problem/392/C
/**/
#define int long long
#define ll long long
const int N = 103;
int sum(ll x, ll y)
{
x += y;
if (x >= MOD)
return x - MOD;
return x;
}
int mult(ll x, ll y)
{
x%=MOD ;
y%=MOD ;
return (x * y) % MOD;
}
struct Matrix
{
ll a[N+1][N+1];
Matrix()
{
for (int i = 1; i <=N; i++)
for (int j = 1; j <=N; j++)
a[i][j] = 0;
}
Matrix operator * (const Matrix &X) const
{
Matrix res;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
{
res.a[i][j] = 0;
for (int h = 1; h <=N; h++)
{
res.a[i][j] = sum(res.a[i][j], mult(a[i][h], X.a[h][j]));
}
}
return res;
}
};
Matrix bin_pow(Matrix x, ll pow)
{
if (pow == 1) return x;
if (pow == 2) return x * x;
if (pow & 1) return x * bin_pow(x, pow - 1);
return bin_pow(bin_pow(x, pow / 2), 2);
}
Matrix generate() // make your own matrix...
{
Matrix A;
for(int i=2;i<=100;++i)
A.a[i][i-1]=1 ;
for(int i=1;i<=100;++i)
A.a[i][100]=A.a[i][101]=cnt[100-i+1] ;
A.a[101][101]=1 ;
return A;
}
----------------------------------------------------------------------
// template ends here.
// you can ignore...