比赛 |
20241025 |
评测结果 |
AAAAAAAAAA |
题目名称 |
九连环 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
0.032 s |
代码语言 |
C++ |
内存使用 |
3.53 MiB |
提交时间 |
2024-10-25 07:44:26 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 1e5+10;
const ll mod = 998244353;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
ll n,f[N];
struct Matrix{
ll c[3][3];
void clear(){memset(c,0,sizeof c);}
Matrix operator * (const Matrix x)const{
Matrix y;y.clear();
for(int i = 0;i < 3;i++)
for(int j = 0;j < 3;j++)
for(int k = 0;k < 3;k++)(y.c[i][j] += c[i][k] * x.c[k][j] % mod) %= mod;
return y;
}
}F,U;
int main(){
freopen("X.in","r",stdin);
freopen("X.out","w",stdout);
n = read();
F.c[0][0] = 2,F.c[0][1] = 1,F.c[0][2] = 1;
if(n == 1)return printf("1\n"),0;
if(n == 2)return printf("2\n"),0;
n -= 2;
U.c[0][0] = 1,U.c[1][0] = 2,U.c[2][0] = 1;
U.c[0][1] = 1,U.c[2][2] = 1;
while(n){
if(n & 1)F = F * U;
U = U * U;n >>= 1;
}
printf("%lld\n",F.c[0][0]);
return 0;
}