斐波那契级数除以N会出现循环,此周期称为皮萨诺周期。

下面给出证明

必然会出现循环
 这是基于下面事实:
 1. R(n+2)=F(n+2) mod P=(F(n+1)+F(n)) mod P=(F(n+1) mod p +F(n) modp) mod p
 2. 斐波那契数列的最大公约数定理:gcd(F(m),F(n))=F(gcd(m,n))
 最大公约数定理表明如果F(k)能被N整除,则F(ik)也能被N整除,这就表明了斐波那契数列所含因子的周
期性,下面列举:
 因子:2,3,4,5, 6,7,8, 9,10,11,12
 周期:3,4,6,5,12,8,6,12,15,10,12
 我们称所生成的序列为剩余序列,那么一旦出现某个F(k) 能被N整除(这需证明我的一个猜想:对于任意
素数P,F(P),F(P-1)和F(P+1)三个中定有一个能被P整除),以后F(ik)都能被N整除,亦即剩余
序列周期地出现0,
下一个剩余序列值为N-1种可能,总会重复,有两个相邻的重复该序列就一定重复,亦即具有周期性。
 这个周期叫做皮萨诺周期

而这个周期长度不会超过6P

当我们所要求的Fib数列项数特别大的时候,我们就可以用周期性来优化了

下面给个快速幂矩阵的FIB数列代码

const mol=;

type matrix=array[..,..] of int64;
var
c,cc:matrix;
n:int64; function multiply(x,y:matrix):matrix; inline;
var temp:matrix;
begin
temp[,]:=(x[,]*y[,]+x[,]*y[,]) mod mol;
temp[,]:=(x[,]*y[,]+x[,]*y[,]) mod mol;
temp[,]:=(x[,]*y[,]+x[,]*y[,]) mod mol;
temp[,]:=(x[,]*y[,]+x[,]*y[,]) mod mol;
exit(temp);
end; function getcc(n:int64):matrix; inline;
var temp:matrix;
t:int64;
begin
if n= then exit(c);
t:=n>>;
temp:=getcc(t);
temp:=multiply(temp,temp);
if (n and )= then exit(multiply(temp,c))
else exit(temp);
end; procedure init;
begin
readln(n);
c[,]:=;
c[,]:=;
c[,]:=;
c[,]:=;
if n= then
begin
writeln();
halt;
end;
if n= then
begin
writeln();
halt;
end;
cc:=getcc(n-);
end; procedure work;
begin
writeln(int64(cc[,]+cc[,]) mod mol);
end; begin
init;
work;
end.
												

FIB数列的更多相关文章

  1. bzoj5104: Fib数列

    Description Fib数列为1,1,2,3,5,8... 求在Mod10^9+9的意义下,数字N在Fib数列中出现在哪个位置 无解输出-1 Input 一行,一个数字N,N < = 10 ...

  2. 动态规划之Fib数列类问题应用

    一,问题描述 有个小孩上楼梯,共有N阶楼梯,小孩一次可以上1阶,2阶或者3阶.走到N阶楼梯,一共有多少种走法? 二,问题分析 DP之自顶向下分析方式: 爬到第N阶楼梯,一共只有三种情况(全划分,加法原 ...

  3. UVaLive 3357 Pinary (Fib数列+递归)

    题意:求第 k 个不含前导 0 和连续 1 的二进制串. 析:1,10,100,101,1000,...很容易发现长度为 i 的二进制串的个数正好就是Fib数列的第 i 个数,因为第 i 个也有子问题 ...

  4. 【bzoj5118】Fib数列2 费马小定理+矩阵乘法

    题目描述 Fib定义为Fib(0)=0,Fib(1)=1,对于n≥2,Fib(n)=Fib(n-1)+Fib(n-2) 现给出N,求Fib(2^n). 输入 本题有多组数据.第一行一个整数T,表示数据 ...

  5. HDU3977 Evil teacher 求fib数列模p的最小循环节

    In the math class, the evil teacher gave you one unprecedented problem! Here f(n) is the n-th fibona ...

  6. 1022. Fib数列

    https://acm.sjtu.edu.cn/OnlineJudge/problem/1022 Description 定义Fib数列:1,1,2,3,5,8,13,…1,1,2,3,5,8,13, ...

  7. [bzoj5118]Fib数列2_费马小定理_矩阵乘法

    Fib数列2 bzoj-5118 题目大意:求Fib($2^n$). 注释:$1\le n\le 10^{15}$. 想法:开始一看觉得一定是道神题,多好的题面啊?结果...妈的,模数是质数,费马小定 ...

  8. 【BZOJ5104】Fib数列(BSGS,二次剩余)

    [BZOJ5104]Fib数列(BSGS,二次剩余) 题面 BZOJ 题解 首先求出斐波那契数列的通项: 令\(A=\frac{1+\sqrt 5}{2},B=\frac{1-\sqrt 5}{2}\ ...

  9. @bzoj - 5104@ Fib数列

    目录 @description@ @solution@ @accepted code@ @details@ @description@ Fib数列为1,1,2,3,5,8... 求在Mod10^9+9 ...

随机推荐

  1. .net string format

    转自:http://www.cnblogs.com/jobs2/p/3948049.html 转自:http://jingyan.baidu.com/article/48206aeaf8c52f216 ...

  2. js 数字

    var text = $("#iptNum").val(); if(isNaN(text)){ alert("不是数字"); } else{ alert(&qu ...

  3. CXF 调用C#.net的WebService

    原文链接:http://hi.baidu.com/pengfeiiw/blog/item/3203e29065aa3a8aa977a4d0.html 1.编写C#.net的WebService Ser ...

  4. 利用mapreduce清洗日志内存不足问题

    package com.libc; import java.io.IOException; import java.io.UnsupportedEncodingException; import ja ...

  5. Building Workspace速度慢的原因

    今天把ext3.0部署到web project很慢很慢,查了一下,这个当笔记. 转自http://blog.163.com/jong_cai/blog/static/87028045201311178 ...

  6. Visual Studio之Nuget

    一.NuGet是什么? NuGet是一个为大家所熟知的Visual Studio扩展,通过这个扩展,开发人员可以非常方便地在Visual Studio中安装或更新项目中所需要的第三方组件,同时也可以通 ...

  7. js处理json的方法

    var json = "{id:"myid", url:"http://www.myurl.com"}"; var js= (new Fun ...

  8. javaTemplates-学习笔记一

    第一步,下载Java运行环境-JDK JDK -'1.8.0_25'[附链接地址] 安装JDK配置环境 安装好jdk,然后配置环境变量.不同系统配置环境变量百度Google之,附上WIN8配置方法[J ...

  9. HTML禁止使用右键

    <html> <script type="text/javascript"> <!-- document.oncontextmenu=function ...

  10. Checking Network Configuration requirements Failed

    安装oracle执行检查,出现 Checking Network Configuration requirements ... Check complete. The overall result o ...