天使的分裂
题目大意
同时满足
求 ∑ni=1Fi
数据范围
题解
题目很简单,但是看上去很难。
先将F的递推式推出来。
所以递推式为 Fn = Fn−1 + Fn−2 + fn
再套个5*5的矩阵乘法这一题就切了。(矩阵构造很简单,请大家自行思考)
Code(Pascal)
const
mo=998244353;
var
jz,zy,ok,new:array[0..5,0..5] of int64;
n:int64;
procedure makejz;
begin
jz[1,2]:=1;
jz[2,1]:=1;
jz[2,2]:=1;
jz[3,4]:=1;
jz[4,3]:=1;
jz[4,4]:=1;
jz[4,2]:=1;
jz[4,1]:=1;
jz[5,5]:=1;
jz[5,4]:=1;
jz[5,3]:=1;
jz[5,2]:=1;
jz[5,1]:=1;
end;
procedure lj;
var
i,j,l:longint;
begin
for i:=1 to 5 do
for j:=1 to 5 do
begin
new[i,j]:=0;
for l:=1 to 5 do
new[i,j]:=(new[i,j]+zy[i,l]*ok[l,j]) mod mo;
end;
zy:=new;
end;
procedure xc;
var
i,j,l:longint;
begin
for i:=1 to 5 do
for j:=1 to 5 do
begin
new[i,j]:=0;
for l:=1 to 5 do
new[i,j]:=(new[i,j]+ok[i,l]*ok[l,j]) mod mo;
end;
ok:=new;
end;
procedure ksm(o:int64);
begin
while o>0 do
begin
if o mod 2=1 then lj;
o:=o div 2;
xc;
end;
end;
begin
readln(n);
if n=0 then writeln(1)
else if n=1 then writeln(3)
else
begin
makejz;
zy:=jz;
ok:=jz;
ksm(n-2);
writeln((zy[5,5]*3+zy[5,4]*2+zy[5,3]+zy[5,2]+zy[5,1]) mod mo);
end;
end.