跳到正文

题解

题解 P1306 【斐波那契公约数】

81x92约 2 分钟
原文
文章信息与版本

文章信息

发布
2020年1月19日
收录
2025年12月12日
更新
2026年9月23日
篇幅
约 2 分钟
获赞
8
题目
P1306

版本

  1. v1当前

这里提供另一种证明方法:

证明:gcd(Fn,Fm)=Fgcd(n,m)gcd(F_n,F_m)=F_{gcd(n,m)}

斐波那契数列的通项公式大家应该都知道:Fn=(1+52)n−(1−52)n5F_n=\dfrac{(\dfrac{1+\sqrt{5}}{2})^n-(\dfrac{1-\sqrt{5}}{2})^n}{\sqrt{5}}

那么我们把gcdgcd里的式子展开可以得到:gcd(Fn,Fm)=gcd((1+52)n−(1−52)n5,(1+52)m−(1−52)m5)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}})

同乘5\sqrt{5}、整理得:5gcd(Fn,Fm)=gcd((1+52)n−(1−52)n,(1+52)m−(1−52)m)\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)

∴5gcd(Fn,Fm)=(1+52)gcd(n,m)−(1−52)gcd(n,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)}

∴gcd(Fn,Fm)=(1+52)gcd(n,m)−(1−52)gcd(n,m)5=Fgcd(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)}

所以,我们只需要用矩阵快速幂求出Fgcd(n,m)F_{gcd(n,m)}即可得到gcd(Fn,Fm)gcd(F_n,F_m)。

原文
存档评论4 条抓取于