其他分享
首页 > 其他分享> > 【笔记】斐波那契数列

【笔记】斐波那契数列

作者:互联网

定义

\[\large F_n = \begin{cases} 0&n = 0\\ 1&n = 1\\ F_{n-2}+F_{n-1}&\operatorname{otherwise}.\end{cases}\]

通项公式

\[\large F_n = \frac{\left(\frac{1+\sqrt 5}{2}\right)^n-\left(\frac{1-\sqrt 5}{2}\right)^n}{\sqrt 5} \]

矩阵加速递推

\[\large\begin{bmatrix}F_{n-1}&F_n\end{bmatrix} = \begin{bmatrix}F_{n-2}&F_{n-1}\end{bmatrix}\times\begin{bmatrix}0&1\\1&1\end{bmatrix} \]

\[\begin{bmatrix}F_n &F_{n+1}\end{bmatrix} = \begin{bmatrix}F_0&F_1\end{bmatrix}\times\begin{bmatrix}0&1\\1&1\end{bmatrix}^n \]

快速倍增

\[F_{2\cdot k} = F_k\times(2\cdot F_{k+1}-F_k) \]

\[F_{2\cdot k+1} = F_{k+1}^2+F_{k}^2 \]

#define ull unsigned long long
std :: pair<ull,ull> Fibonacci(int k) {
	if(k == 0) 
		return std :: make_pair(0,1);
	std :: pair<ull,ull> receive = Fibonacci(k>>1);
	ull r_a = receive.first*((receive.second<<1)-receive.first);
	ull r_b = receive.first*receive.first+receive.second*receive.second;
	if(k&1) 
		return std :: make_pair(r_b,r_a+r_b);
	else
		return std :: make_pair(r_a,r_b);
}

性质

  1. \(F_{n-1}\times F_{n+1}-F_n^2 = (-1)^n\)

  2. \(F_{n+k} = F_k\times F_{n+1}+F_{k-1}\times F_n\)

  3. \(F_a\mid F_b\iff a\mid b\)

  4. \(\gcd(F_a,F_b) = F_{\gcd(a,b)}\)

周期

标签:begin,end,数列,sqrt,times,斐波,bmatrix,frac,那契
来源: https://www.cnblogs.com/bikuhiku/p/Fibonacci.html