F. Lunar New Year and a Recursive Sequence(矩阵快速幂+BSGS)
Posted H-w-H
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了F. Lunar New Year and a Recursive Sequence(矩阵快速幂+BSGS)相关的知识,希望对你有一定的参考价值。
F. Lunar New Year and a Recursive Sequence
题意:
给出
f
1
=
f
2
=
⋯
=
f
k
−
1
=
1
f_1=f_2=\\cdots=f_{k-1}=1
f1=f2=⋯=fk−1=1和
b
1
,
b
2
⋯
b
k
b_1,b_2\\cdots b_k
b1,b2⋯bk,还有递推方程
f
i
=
f
i
−
1
b
1
f
i
−
2
b
2
⋯
f
i
−
k
b
k
f_i=f_{i-1}^{b_1}f_{i-2}^{b_2}\\cdots f_{i-k}^{b_k}\\\\
fi=fi−1b1fi−2b2⋯fi−kbk
问是否存在一个 f k f_k fk使得 f n ≡ m ( m o d p ) f_n\\equiv m(mod~p) fn≡m(mod p)成立;
思路:
矩阵快速幂 + B S G S +BSGS +BSGS
因为 n n n很大,所以不能直接推出 f n f_n fn是 f k f_k fk的多少次方,观察递推式全是乘法,我们就想到用矩阵加速。
先推出矩阵。
假设
k
=
4
k=4
k=4,则可以推出下面的式子。
f
k
=
f
k
f
k
+
1
=
f
k
b
1
f
k
−
1
b
2
f
k
−
2
b
3
f
k
−
3
b
4
=
f
k
b
1
f
k
+
2
=
f
k
+
1
b
1
f
k
b
2
f
k
−
1
b
3
f
k
−
2
b
4
=
(
f
k
b
1
)
b
1
f
k
b
2
=
f
k
b
1
2
+
b
2
f
k
+
3
=
f
k
+
2
b
1
f
k
+
1
b
2
f
k
b
3
f
k
−
1
b
4
=
f
k
b
1
3
+
2
b
1
∗
b
2
+
b
3
f
k
+
4
=
f
k
+
3
b
1
f
k
+
2
b
2
f
k
+
1
b
3
f
k
b
4
=
f
k
b
1
4
+
3
b
1
2
b
2
+
2
b
1
b
3
+
b
2
2
+
b
4
f
k
+
5
=
f
k
+
4
b
1
f
k
+
3
b
2
f
k
+
2
b
3
f
k
+
1
b
1
\\begin{aligned} &f_k=f_k\\\\ &f_{k+1}=f_k^{b_1}f_{k-1}^{b_2}f_{k-2}^{b_3}f_{k-3}^{b_4}=f_k^{b_1}\\\\ &f_{k+2}=f_{k+1}^{b_1}f_k^{b_2}f_{k-1}^{b_3}f_{k-2}^{b_4}=(f_k^{b_1})^{b_1}f_k^{b_2}=f_k^{b_1^2+b_2}\\\\ &f_{k+3}=f_{k+2}^{b_1}f_{k+1}^{b_2}f_k^{b_3}f_{k-1}^{b_4}=f_k^{b_1^3+2b_1*b_2+b_3}\\\\ &f_{k+4}=f_{k+3}^{b_1}f_{k+2}^{b_2}f_{k+1}^{b_3}f_k^{b_4}=f_k^{b_1^4+3b_1^2b_2+2b_1b_3+b_2^2+b_4}\\\\ &f_{k+5}=f_{k+4}^{b_1}f_{k+3}^{b_2}f_{k+2}^{b_3}f_{k+1}^{b_1}\\\\ \\end{aligned}
fk=fkfk+1=fkb1fk−1b2fk−2b3fk−3b4=fkb1fk+2=fk+1b1fkb2fk−1b3fk−2b4=(fkb1)b1fkb2=fkb12+b2fk+3=fk+2b1fk+1b2f
Codeforces Round #536 (Div. 2) - D. Lunar New Year and a Wander(最短路)
CF1106F Lunar New Year and a Recursive Sequence
Codeforces 1106C Lunar New Year and Number DivisionLunar |数学
CF1106F Lunar New Year and a Recursive Sequence——矩阵快速幂&&bsgs
CF1106F Lunar New Year and a Recursive Sequence(矩阵快速幂+bsgs+exgcd)
Codeforces 536F Lunar New Year and a Recursive Sequence | BSGS/exgcd/矩阵乘法