Fibonacci 1

题面

\[F_0=0,F_1=1,F_n=F_{n-1}+F_{n-2}
\]

给定\(n\),求

\[S(n)=\sum_{i=1}^{n}F_nF_{n-1}
\]

数据格式

第一行一个整数t表示数据组数.

以下每一行一组测试数据,两个整数\(n\)和\(p\),表示求\(S(n)\bmod p\).

数据范围

\(t\le 100000\)

\(n\le 10^{18}\)

样例输入

10
17 2108
19 93892
21 5461
21 25577
21 22576
17 75829
18 12144
16 64340
29 70121
18 51995

样例输出

782
16848
575
12247
4083
48051
3928
9069
54607
21696

解释

Fib数列:

0 1 1 2 3

5 8 13 21 34

55 89 144 233 377

610 987 1597 2584 4181

6765 10946 17711 28657 46368

75025 121393 196418 317811 514229

832040

Fib[n]Fib[n-1]数列前缀和

0 1 3 9 24 64

168 441 1155 3025 7920 20736

54288 142129 372099 974169 2550408 6677056

17480760 45765225 119814915 313679521 821223648 2149991424

5628750624 14736260449 38580030723 101003831721 264431464440 692290561600

模64340

0       1       3       9       24      64
168 441 1155 3025 7920 20736
54288 13449 50399 9069 41148 50036
44620 19485 13835 22021 52228 5984
30064 19869 29543 4421 48060 11080

模70121

0       1       3       9       24      64
168 441 1155 3025 7920 20736
54288 1887 21494 62596 26052 15561
20631 46333 48247 28288 36617 11443
67833 51815 17491 659 54607 22921

Fibonacci 1的更多相关文章

  1. 算法与数据结构(九) 查找表的顺序查找、折半查找、插值查找以及Fibonacci查找

    今天这篇博客就聊聊几种常见的查找算法,当然本篇博客只是涉及了部分查找算法,接下来的几篇博客中都将会介绍关于查找的相关内容.本篇博客主要介绍查找表的顺序查找.折半查找.插值查找以及Fibonacci查找 ...

  2. #26 fibonacci seqs

    Difficulty: Easy Topic: Fibonacci seqs Write a function which returns the first X fibonacci numbers. ...

  3. 关于java的递归写法,经典的Fibonacci数的问题

    经典的Fibonacci数的问题 主要想展示一下迭代与递归,以及尾递归的三种写法,以及他们各自的时间性能. public class Fibonacci { /*迭代*/ public static ...

  4. 斐波拉契数列(Fibonacci) 的python实现方式

    第一种:利用for循环 利用for循环时,不涉及到函数,但是这种方法对我种小小白来说比较好理解,一涉及到函数就比较抽象了... >>> fibs = [0,1] >>&g ...

  5. fibonacci数列(五种)

    自己没动脑子,大部分内容转自:http://www.jb51.net/article/37286.htm 斐波拉契数列,看起来好像谁都会写,不过它写的方式却有好多种,不管用不用的上,先留下来再说. 1 ...

  6. POJ3070 Fibonacci[矩阵乘法]

    Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13677   Accepted: 9697 Descri ...

  7. Fibonacci 数列算法分析

    /************************************************* * Fibonacci 数列算法分析 ****************************** ...

  8. 算法系列:Fibonacci

    Copyright © 1900-2016, NORYES, All Rights Reserved. http://www.cnblogs.com/noryes/ 欢迎转载,请保留此版权声明. -- ...

  9. UVa #11582 Colossal Fibonacci Numbers!

    巨大的斐波那契数 The i'th Fibonacci number f (i) is recursively defined in the following way: f (0) = 0 and  ...

  10. Buge's Fibonacci Number Problem

    Buge's Fibonacci Number Problem Description snowingsea is having Buge’s discrete mathematics lesson, ...

随机推荐

  1. PHP----遇到的Session问题

    使用SESSION,当跨页面使用时,会提示错误Cannot modify header information - headers already sent by..., 背景:使用session_s ...

  2. 安装weinre在PC端调试移动端

    1.使用node安装weinre. 2.启动weinre, weinre --httpPort 8081  --boundHost -all- 3.在浏览器打开 http://localhost:80 ...

  3. ecshop后台模板设置中将非可编辑区改为可编辑区

    原代码 <file name="category.dwt"> <region name="左边区域"> <lib>cart& ...

  4. draw9的使用说明

    转载来自:http://isux.tencent.com/android-ui-9-png.html 在Android的设计过程中,为了适配不同的手机分辨率,图片大多需要拉伸或者压缩,这样就出现了可以 ...

  5. Lua弱引用table

    弱引用table 与python等脚本语言类似地,Lua也采用了自动内存管理(Garbage Collection),一个程序只需创建对象,而无需删除对象.通过使用垃圾收集机制,Lua会自动删除过期对 ...

  6. JavaScript 五种(构造方式)继承

    一.对象冒充 function Parent(username){ this.username = username; this.hello = function(){ alert(this.user ...

  7. Redis命令大全&中文解释&在线测试命令工具&在线中文文档

    在线测试命令地址:http://try.redis.io/ 官方文档:http://redis.io/commands http://redis.io/documentation Redis 命令参考 ...

  8. [C#]如何使用ThreadPool

    摘要 线程池是一种多线程的形式,其中的任务被添加到队列中,并在创建线程时自动启动. 以下示例使用.Net框架的线程池来计算十个数字20和40之间的裴波那契的结果.裴波那契Fibonacci类,它提供了 ...

  9. CF461B Appleman and Tree (树DP)

    CF462D Codeforces Round #263 (Div. 2) D Codeforces Round #263 (Div. 1) B B. Appleman and Tree time l ...

  10. GOF业务场景的设计模式-----观察者模式

    定义:定义对象间一种一对多的依赖关系,使得当每一个对象改变状态,则所有依赖于它的对象都会得到通知并自动更新. 在软件系统中经常会有这样的需求:如果一个对象的状态发生改变,某些与它相关的对象也要随之做出 ...