ZROI1119 【十一·联考】幸福

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
#include<cmath>
const int mod=998244353;
using namespace std;
struct matrix {
ll data[7][7];
void clear() {
//for(int i=1;i<=5;i++)for(int j=1;j<=5;j++)data[i][j]=0;
memset(data,0,sizeof(data));
}
};
inline matrix operator * (matrix &a,matrix &b) {
static matrix ans;ans.clear();
for(int i=1;i<=5;i++) {for(int j=1;j<=5;j++) {for(int k=1;k<=5;k++) {ans.data[i][j]+=a.data[k][j]*b.data[i][k];ans.data[i][j]%=mod;}}}
return ans;
}
matrix blank,re,E;
void init() {
//re_n=2
for(int i=1;i<=5;i++)E.data[i][i]=1;
re.data[1][1]=1;
re.data[2][1]=2;
re.data[3][1]=1;
re.data[4][1]=1;
re.data[5][1]=3;
blank.data[1][2]=1;blank.data[2][1]=1;blank.data[2][2]=1;blank.data[2][3]=1;blank.data[2][4]=1;blank.data[3][4]=1;
blank.data[4][3]=1;blank.data[4][4]=1;blank.data[5][1]=1;blank.data[5][2]=1;blank.data[5][3]=1;blank.data[5][4]=1;blank.data[5][5]=1;
};
ll n;
matrix ksm(ll time) {
matrix ans,cur;ans.clear();ans=E;cur=blank;
for(;time;time>>=1,cur=cur*cur){
if(time&1)ans=ans*cur;
}
return ans;
}
int main() {
init();
scanf("%lld",&n);
if(n==1){printf("3");return 0;}