ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#208293 | #3759. 七 | yhmm | 100 | 1ms | 1196kb | C++11 | 1.6kb | 2024-08-02 09:38:47 | 2024-08-02 12:08:40 |
answer
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
long long n,mod=998244353;
struct Matrix
{
long long data[5][5],r,c;
Matrix()
{
memset(data,0,sizeof data);
}
Matrix(int _r,int _c):r(_r),c(_c)
{
memset(data,0,sizeof data);
}
Matrix operator+(const Matrix &t)const
{
Matrix res;
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
res.data[i][j]=(data[i][j]+t.data[i][j])%mod;
}
}
return res;
}
// Matrix operator*(const Matrix &t)const
// {
// Matrix res;
// res.r=r,res.c=t.c;
// for(int i=1;i<=r;i++)
// {
// for(int j=1;j<=t.c;j++)
// {
// for(int k=1;k<=t.r;k++)
// {
// res.data[i][j]=(((data[i][k]*t.data[k][j])%mod)+res.data[i][j])%mod;
// }
// }
// }
// return res;
// }
Matrix operator*(const Matrix &t)const
{
Matrix res;
res.r=r,res.c=t.c;
for(int i=1;i<=r;i++)
{
for(int k=1;k<=t.r;k++)
{
long long tmp=data[i][k];
for(int j=1;j<=t.c;j++)
{
res.data[i][j]=(tmp*t.data[k][j]+res.data[i][j])%mod;
}
}
}
return res;
}
Matrix operator^(long long x)const
{
Matrix res(r,r),base(r,r);
for(int i=1;i<=r;i++)
{
res.data[i][i]=1;
}
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
base.data[i][j]=data[i][j];
}
}
while(x)
{
if(x&1)
{
res=res*base;
}
base=base*base;
x>>=1;
}
return res;
}
};
int main(){
cin>>n;
Matrix a(2,2),b(2,1);
a.data[1][1]=10;
a.data[1][2]=1;
a.data[2][1]=0;
a.data[2][2]=9;
b.data[1][1]=0;
b.data[2][1]=1;
a=a^n;
a=a*b;
cout<<a.data[1][1];
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1196kb
input:
5
output:
40951
result:
ok single line: '40951'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1196kb
input:
6
output:
468559
result:
ok single line: '468559'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1192kb
input:
55555
output:
804269613
result:
ok single line: '804269613'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1192kb
input:
66666
output:
564026970
result:
ok single line: '564026970'
Test #5:
score: 10
Accepted
time: 0ms
memory: 1196kb
input:
77777
output:
11325516
result:
ok single line: '11325516'
Test #6:
score: 10
Accepted
time: 0ms
memory: 1196kb
input:
99999
output:
103114180
result:
ok single line: '103114180'
Test #7:
score: 10
Accepted
time: 0ms
memory: 1192kb
input:
987654321
output:
199913509
result:
ok single line: '199913509'
Test #8:
score: 10
Accepted
time: 0ms
memory: 1196kb
input:
999999999
output:
107253766
result:
ok single line: '107253766'
Test #9:
score: 10
Accepted
time: 0ms
memory: 1192kb
input:
938281736
output:
654499906
result:
ok single line: '654499906'
Test #10:
score: 10
Accepted
time: 1ms
memory: 1192kb
input:
837271623
output:
48926228
result:
ok single line: '48926228'
Extra Test:
score: 0
Extra Test Passed