比赛 |
20241025 |
评测结果 |
AAAAAAAAAA |
题目名称 |
九连环 |
最终得分 |
100 |
用户昵称 |
darkMoon |
运行时间 |
0.032 s |
代码语言 |
C++ |
内存使用 |
3.58 MiB |
提交时间 |
2024-10-25 07:52:28 |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
auto IN = freopen("X.in", "r", stdin);
auto OUT = freopen("X.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 1e6 + 5, MOD = 998244353;
int n = mread();
struct node{
int a[4][4];
node(){
for(int i = 0; i < 4; i ++){
for(int j = 0; j < 4; j ++){
a[i][j] = 0;
}
}
}
node friend operator * (node a, node b){
node ans;
for(int i = 0; i < 4; i ++){
for(int j = 0; j < 4; j ++){
for(int k = 0; k < 4; k ++){
(ans.a[i][j] += a.a[i][k] * b.a[k][j] % MOD) %= MOD;
}
}
}
return ans;
}
}f, s;
node ksm(node now, int k){
node ans;
for(int i = 0; i < 4; i ++){
ans.a[i][i] = 1;
}
while(k){
if(k & 1){
ans = ans * now;
}
now = now * now;
k >>= 1;
}
return ans;
}
signed main(){
f.a[0][0] = 0;
f.a[0][1] = 1;
f.a[0][2] = 2;
f.a[0][3] = 1;
s.a[1][0] = 1;
s.a[2][1] = 1;
s.a[1][2] = 2;
s.a[2][2] = 1;
s.a[3][2] = 1;
s.a[3][3] = 1;
f = f * ksm(s, n - 2);
if(n == 1){
printf("1\n");
}
else{
printf("%lld\n", f.a[0][2]);
}
// f[0] = 0;
// f[1] = 1;
// f[2] = 2;
// for(int i = 3; i <= n; i ++){
// f[i] = 2 * f[i - 2] + f[i - 1] + 1;
// }
// printf("%lld", f[n]);
return 0;
}