http://www.lydsy.com/JudgeOnline/problem.php?id=3231   和斐波那契一个道理在最后加一个求和即可 #include<cstdio> #include<cstring> #include<iostream> //using namespace std; ; ; long long modn; long long n,l,r; ]={}; struct mat{ ][]; mat(){ memset(e,,sizeof(e…
矩阵乘法裸题..差分一下然后用矩阵乘法+快速幂就可以了. --------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm>   using namespace std;   const int maxn = 20;   typedef long long ll; t…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3231 矩阵乘法裸题. 1018是10^18.别忘了开long long. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define ll long long using namespace std; ; int n; ll L,R,b[N],c[N…
今天真是莫名石乐志 一眼矩阵乘法,但是这个矩阵的建立还是挺有意思的,就是把sum再开一列,建成大概这样 然后记!得!开!long!long!! #include<iostream> #include<cstdio> using namespace std; const int N=20; long long n,b[N],c[N],sum,l,r,mod; struct jz { long long a[N][N]; jz operator * (const jz &b)…
fibonacci数列(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, - An alter…
描述 In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, - An alternative formula for the Fibonacci sequence is . Given…
题目分析: 对于给出的n,求出斐波那契数列第n项的最后4为数,当n很大的时候,普通的递推会超时,这里介绍用矩阵快速幂解决当递推次数很大时的结果,这里矩阵已经给出,直接计算即可 #include<iostream> #include<stdio.h> using namespace std; ; struct mat{ ][]; }; mat operator * (mat a, mat b){ //重载乘号,同时将数据mod10000 mat ret; ; i < ; i++…
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=5118 题解 这个题一看就是不可做的样子. 求斐波那契数列的第 \(n\) 项,\(n \leq 2^{10^{15}}\)??? 这样人怎么矩阵快速幂啊. 等等这个模数很神奇啊. \(1125899839733759\) 好像是一个质数,还以 \(9\) 结尾. 那么 \(5\) 对于 \(1125899839733759\) 一定有二次剩余咯. 那么根据 Fib 的通项公式 \[ f(n)…
题意:a1=0;a2=1;a3=2; a(n)=a(n-1)+a(n-2)+a(n-3);  求a(n) 思路:矩阵快速幂 #include<cstdio> #include<cstring> #define ll long long #define mod int(1e9+9) struct jz { ll num[][]; jz(){ memset(num, , sizeof(num)); } jz operator*(const jz&p)const { jz ans…
题目链接 先考虑 假设S确定,使构造S操作次数最小的方案应是:对T建SAM,S在SAM上匹配,如果有S的转移就转移,否则操作数++,回到根节点继续匹配S.即每次操作一定是一次极大匹配. 简单证明:假设S="ABCD",T有子串"A","AB","CD","BCD",那么步数最小方案是选"AB"再接上"CD",而不是提前断开选择"A"+"B…