Problem - 3936 FIB Query
题目链接
Problem Description
We all know the definition of Fibonacci series: fib[i]=fib[i-1]+fib[i-2],fib[1]=1,fib[2]=1.And we define another series P associated with the Fibonacci series: P[i]=fib[4*i-1].Now we will give several queries about P:give two integers L,R, and calculate ∑P[i](L <= i <= R).
Input
There is only one test case.The first line contains single integer Q – the number of queries. (Q<=10^4)Each line next will contain two integer L, R. (1<=L<=R<=10^12)
Output
For each query output one line.Due to the final answer would be so large, please output the answer mod 1000000007.
Sample Input
2
1 300
2 400
Sample Output
838985007
352105429
AC
- 经过以下推导,只用求单个斐波那契值即可,因为n比较大,用矩阵快速幂
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <map>
#include <bitset>
#include <set>
#include <string.h>
#include <cmath>
#include <queue>
#include <algorithm>
#define N 100005
#define P pair<int,int>
#define ll long long
#define lowbit(a) a&(-a)
#define mk(a, b) make_pair(a, b)
#define mem(a, b) memset(a, b, sizeof(a))
ll mod = 1e9 +7;
using namespace std;
// 矩阵相乘
void mul(ll a[][2], ll b[][2]) {ll ans[2][2];for (int i = 0; i < 2; ++i) {for (int j = 0; j < 2; ++j) {ans[i][j] = a[i][0] * b[0][j] + a[i][1] * b[1][j];}}a[0][0] = ans[0][0] % mod;a[0][1] = ans[0][1] % mod;a[1][0] = ans[1][0] % mod;a[1][1] = ans[1][1] % mod;
}
ll x[2][2], t[2][2];
// 矩阵快速幂
void quick(ll num) {x[0][0] = 0;x[0][1] = 1;t[0][0] = 0;t[0][1] = 1;t[1][0] = 1;t[1][1] = 1;while (num) {if (num & 1) {mul(x, t);}num >>= 1;mul(t, t);}
} int main(){
#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);
#endifint t;scanf("%d", &t);while (t--) {ll l, r;scanf("%lld%lld", &l, &r);l--;ll sumr, suml;quick(2 * r);sumr = x[0][0] * x[0][1] % mod;quick(2 * l);suml = x[0][0] * x[0][1] % mod;ll ans = sumr - suml;printf("%lld\n", (ans + mod) % mod);}#ifndef ONLINE_JUDGEfclose(stdin);fclose(stdout);system("out.txt");
#endifreturn 0;
}
Problem - 3936 FIB Query相关推荐
- oracle查询挂起,表挂起更新查询Oracle 11g(Table hangs on Update query Oracle 11g)
表挂起更新查询Oracle 11g(Table hangs on Update query Oracle 11g) 我正在更新一个Oracle表字段,引用另一个具有类似Key字段的表,但在此特定表上, ...
- 第 2 届河北省大学生程序设计竞赛(河北省赛)-Problem G. 520-题解
传送门 Problem A. Mex Query Problem B. Nim Game Problem C. icebound 的账单 Problem G. 520 Problem H. 神殿 Pr ...
- 第 2 届河北省大学生程序设计竞赛(河北省赛)-Problem B. Nim Game-题解
传送门 Problem A. Mex Query Problem B. Nim Game Problem C. icebound 的账单 Problem G. 520 Problem H. 神殿 Pr ...
- 第 2 届河北省大学生程序设计竞赛(河北省赛)-Problem H. 神殿-题解
传送门 Problem A. Mex Query Problem B. Nim Game Problem C. icebound 的账单 Problem G. 520 Problem H. 神殿 Pr ...
- 零知识证明实践教程,第三部分
本文是零知识证明简单实践教程的第三部分, 第一部分见:零知识证明第一部分, 第二部分见:零知识证明第二部分. 下面这个图片是我们在第二部分所使用的merkle树来构造prover的承诺.同时我们也提出 ...
- 关系型数据库是如何运作的
一说到关系型数据库,我总感觉缺了点什么.如果你尝试透过"关系型数据库是如何运作的"的关键词句来进行搜索,其搜索结果是少量的而且内容是简短的.难道说是由于它已经太老旧而已经不再流行吗 ...
- 如果有人问你关系数据库的工作原理,叫他看这篇文章How does a relational database work
When it comes to relational databases, I can't help thinking that something is missing. They're used ...
- 杭电多校第十场 hdu6434 Count 欧拉函数打表 快速打表模板
Problem I. Count Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- SharePoint要在master page中动态显示List数据的几种方式
我们都知道,在SharePoint中,Content page继承自Page layout,而Page layout又继承自Master page.Master page的作用大家都知道,它定义了站点 ...
最新文章
- mysql 的 前导零_将前导零添加到MySQL列?
- [总结] 动态DP学习笔记
- 新时代营销解决方案:敏捷BI助力银行高效精准营销
- Bootstrap4+MySQL前后端综合实训-Day03-PM【iframe设置最小宽度】
- 补码(为什么按位取反再加一):告诉你一个其实很简单的问题
- 00084_Map接口
- 深度解密Go语言之反射
- html设置顶部对齐,HTML / CSS文本从div顶部对齐
- LINQ to XML 操作XML文档
- python plot linestyle 线型颜色及线条控制(linestyle、marker、color)
- sybase jz0c0 连接已关闭_Go 基于 channel 实现连接池
- Silverlight数据驱动模式探索系列 (1)已知列数的DataGrid绑定
- 打开计算机 显示不支持此接口,不支持此接口,教你如何解决电脑Windows系统显示不支持此接口...
- 实战 | 如何使用微搭低代码实现公差申请应用
- 附件文件超过了服务器的大小,Exchange 2010修改附件大小限制
- CREATE DATABASE 或 ALTER DATABASE 失败,因为结果数据库的累计大小将超出每 数据库 为 4096 MB 的
- Python代码实现将png格式图片批量转换为jpg个格式
- 365天英语口语大全
- 一周总结——2020.5.31
- asp.net 是什么?