题解 P1306 【斐波那契公约数】
81x92
·
·
题解
这里提供另一种证明方法:
证明:gcd(F_n,F_m)=F_{gcd(n,m)}
斐波那契数列的通项公式大家应该都知道:F_n=\dfrac{(\dfrac{1+\sqrt{5}}{2})^n-(\dfrac{1-\sqrt{5}}{2})^n}{\sqrt{5}}
那么我们把gcd里的式子展开可以得到:gcd(F_n,F_m)=gcd(\dfrac{(\dfrac{1+\sqrt{5}}{2})^n-(\dfrac{1-\sqrt{5}}{2}
)^n}{\sqrt{5}},\dfrac{(\dfrac{1+\sqrt{5}}{2})^m-(\dfrac{1-\sqrt{5}}{2})^m}{\sqrt{5}})
同乘\sqrt{5}、整理得:\sqrt{5}gcd(F_n,F_m)=gcd((\dfrac{1+\sqrt{5}}{2})^n-(\dfrac{1-\sqrt{5}}{2})^n,(\dfrac{1+\sqrt{5}}{2})^m-(\dfrac{1-\sqrt{5}}{2})^m)
\therefore \sqrt{5}gcd(F_n,F_m)=(\dfrac{1+\sqrt{5}}{2})^{gcd(n,m)}-(\dfrac{1-\sqrt{5}}{2})^{gcd(n,m)}
\therefore gcd(F_n,F_m)=\dfrac{(\dfrac{1+\sqrt{5}}{2})^{gcd(n,m)}-(\dfrac{1-\sqrt{5}}{2})^{gcd(n,m)}}{\sqrt{5}}=F_{gcd(n,m)}
所以,我们只需要用矩阵快速幂求出F_{gcd(n,m)}即可得到gcd(F_n,F_m)。