之前寫的太爛了,重新寫一個
這個名字怎么來的啊
以斐波那契數列\(\{f_n\}\)為例
\[\begin{aligned} f_i &= f_{i - 1} + f_{i - 2}\\ f_1 &= 1, f_2 = 1 \end{aligned} \]
"線性"表示沒有平方項,"常系數"表示沒有系數是變量
"齊次"表示沒有常數項
應該是這樣的
問題引入
1
求\(f_n\;\mathrm{mod}\;10^9 + 7, n \leq 2^{30}\)
這應該是最簡單的了,直接矩陣快速冪
2
van了,這怎么做啊啊啊
\(\mathrm{OGF:}\)我來啦!!!
普通型生成函數自覺起座,秒了此題
設這個數列的生成函數為\(G(x)\)
由遞推式:
\[\begin{aligned} G(x) &= 233xG(x) + 666x^2G(x) + x \\ \therefore G(x) &= \frac{x}{1 - 233x - 666x^2} \\ &= \frac{x}{-666(x_1-x)(x_2-x)} \\ &= \frac{x}{-666(x_1-x_2)} \times\left(\frac{1}{x_1-x}-\frac{1}{x_2 - x}\right)\\ &= \cdots \end{aligned} \]
不想寫了,看這個吧
好麻煩啊,怎么辦啊
特征方程站了起來:
\(a_n=233a_{n-1}+666a_{n-2}\)的特征方程為
\[x^2=233x+666 \\ x^2-233x+666=0 \\ x_1=\frac{233+\sqrt{56953}}2,x_2=\frac{233-\sqrt{56953}}2 \\ \therefore a_n=\alpha x_1^n+\beta x_2^n \\ \because a_0=0,a_1=1 \\ \therefore \begin{cases} \alpha+\beta=0 \\ \alpha x_1+\beta x_2=1 \end{cases} \\ \therefore \begin{cases} \alpha=\frac1{\sqrt{56953}} \\ \beta=-\frac1{\sqrt{56953}} \end{cases} \\ \therefore a_n=\frac1{\sqrt{56953}}\left(\left(\frac{233+\sqrt{56953}}2\right)^n-\left(\frac{233-\sqrt{56953}}2\right)^n\right) \\ \because 188305837^2 \equiv 56953 \; (\text{mod}\;10^9+7) \\ \therefore a_n \equiv 233230706 \times\left(94153035^n-905847205^n\right) \]
解決啦!!!
正題
遞推關系\(a_n = f_1a_{n-1} + f_2a_{n-2} + \cdots + f_ka_{n-k}\)的特征方程為
\[x^k = f_1x^{k-1} + f_2x^{k-2} + \cdots + f_k \]
解出來之后會有很多很多的根,對其進行分類討論
情況一:
\(x\)是\(k\)重根,那么在通項中加入\(f(n)x^n\),其中\(f(n)\)是一個\(k-1\)次多項式,需要待定系數
情況二:
\(x_1,x_2\)是一對共軛復根\(a\pm bi\)
那么在通項中加入:
\[r^n(\alpha cos(n\theta)+\beta sin(n\theta)) \]
其中\(\mathrm{tan}\theta=\frac{b}{a},\;r=\sqrt{a^2+b^2}\)
例題
求
\[\left\lceil (a + \sqrt b) ^ n\right\rceil \% m,\ (a-1)^2 < b < a^2 \]
解:原式為
\[(a+\sqrt b)^n + (a - \sqrt b)^n \]
是不是像情況一的時候的通項公式???
我們可以使用韋達定理還原特征方程,求出遞推式,矩陣快速冪即可。
想不到還有反着推的題目吧