数学--数论--HDU - 6395 Let us define a sequence as below 分段矩阵快速幂
Your job is simple, for each task, you should output Fn module 109+7.
Input
The first line has only one integer T, indicates the number of tasks.
Then, for the next T lines, each line consists of 6 integers, A , B, C, D, P, n.
1≤T≤200≤A,B,C,D≤1091≤P,n≤109
Output
36
24
Sample Input
2
3 3 2 1 3 5
3 2 2 2 1 4
Sample Output
36
24
首先处理递推式这里,因为直接递推会超时,我们考虑矩阵快速幂,然后看题,有三个未知量,我们构造3*3的矩阵,然后因为还有一个数论分块,不能直接使用矩阵快速幂,应该相等的位置使用矩阵快速幂,然后完事了
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
int a, b, c, d, p, n, t;struct mat{int m[3][3];mat(){memset(m, 0, sizeof(mat));}friend mat operator*(mat a, mat b){mat c;for(int i=0; i<3; i++){for(int j=0; j<3; j++){ll t = 0;for(int k=0; k<3; k++){t += (ll)a.m[i][k]*b.m[k][j];}c.m[i][j] = t%mod;}}return c;}
}I;mat pow_mat(mat a, int b){mat c = I;while(b){if(b&1){c = c*a;}a = a*a;b >>= 1;}return c;
}int main(){I.m[0][0] = I.m[1][1] = I.m[2][2] = 1;scanf("%d", &t);while(t--){scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &p, &n);if(n == 1){printf("%d\n", a);continue;}mat f;f.m[0][0] = d;f.m[0][1] = c;f.m[1][0] = 1;f.m[2][2] = 1;int flag = 0;for(int i=3; i<=n;){if(p/i == 0){mat w = f; w = pow_mat(w, n-i+1);ll ans = w.m[0][0]*(ll)b%mod + w.m[0][1]*(ll)a + w.m[0][2]%mod; ans %= mod;printf("%lld\n", ans);flag = 1;break;}int j = min(n, p/(p/i));mat w = f;w.m[0][2] = p/i;w = pow_mat(w, j-i+1);ll tmp1 = (w.m[1][0]*(ll)b + w.m[1][1]*(ll)a + w.m[1][2]) % mod;ll tmp2 = (w.m[0][0]*(ll)b + w.m[0][1]*(ll)a + w.m[0][2]) % mod;a = tmp1; b = tmp2;i = j+1;}if(!flag)printf("%d\n", b);}}
数学--数论--HDU - 6395 Let us define a sequence as below 分段矩阵快速幂相关推荐
- BZOJ 2326 数学作业(分段矩阵快速幂)
实际上,对于位数相同的连续段,可以用矩阵快速幂求出最后的ans,那么题目中一共只有18个连续段. 分段矩阵快速幂即可. #include<cstdio> #include<iostr ...
- HDU 2243考研路茫茫——单词情结 (AC自动机+矩阵快速幂)
背单词,始终是复习英语的重要环节.在荒废了3年大学生涯后,Lele也终于要开始背单词了. 一天,Lele在某本单词书上看到了一个根据词根来背单词的方法.比如"ab",放在单词前一般 ...
- HDU 6185 Covering 矩阵快速幂 递推
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6185 题目描述: 一个4*n的矩形, 你用1*2的矩形覆盖有多少种方案, n <= 1e18 ...
- hdu 5451 Best Solver 矩阵循环群+矩阵快速幂
http://acm.hdu.edu.cn/showproblem.php?pid=5451 题意:给定x 求解 思路: 由斐波那契数列的两种表示方法, 之后可以转化为 线性表示 F[n] = ...
- 【HDU - 4990】 Reading comprehension (构造+矩阵快速幂)
题干: Read the program below carefully then answer the question. #pragma comment(linker, "/STACK ...
- HDU6395 Sequence(矩阵快速幂+数论分块)
题意: F(1)=A,F(2)=B,F(n)=C*F(n-2)+D*F(n-1)+P/n 给定ABCDPn,求F(n) mod 1e9+7 思路: P/n在一段n里是不变的,可以数论分块,再在每一段里 ...
- bzoj 2326: [HNOI2011]数学作业(矩阵快速幂)
2326: [HNOI2011]数学作业 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 2249 Solved: 1301 [Submit][St ...
- HDU 2276 Kiki Little Kiki 2 (位运算+矩阵快速幂)
HDU 2276 Kiki & Little Kiki 2 (位运算+矩阵快速幂) ACM 题目地址:HDU 2276 Kiki & Little Kiki 2 题意: 一排灯,开关 ...
- HDU 4549 M斐波那契数列(矩阵快速幂费马小定理)
ps:今天和战友聊到矩阵快速幂,想到前几天学长推荐去刷矩阵专题,挑了其中唯一一道中文题,没想到越过山却被河挡住去路... 题目链接:[kuangbin带你飞]专题十九 矩阵 R - M斐波那契数列 T ...
最新文章
- Eclipse 搭建Android开发环境(整理)
- 小程序 仿麦当劳_手机上的麦当劳和星巴克:为什么现在首先使用移动应用程序...
- oracle 其他表空间,Oracle查询表空间使用情况以及其他查询
- jdbc mysql 存储过程查询数据_JDBC连接(MySql)数据库步骤,以及查询、插入、删除、更新等十一个处理数据库信息的功能。...
- Flash中与xml交互时不显示中文的解决办法
- php用户名登录名_PHP验证登录用户名和密码
- asp.net捕获全局未处理异常的几种方法
- 【华为云技术分享】《跟唐老师学习云网络》 - Kubernetes网络实现
- 求生欲强烈!HTC官方回应并未退出中国市场
- 达观杯文本智能处理(5)
- Linux:Linux常用网络指令
- Qt qss问题总结
- JSP实用教程(2)——JSP语法
- python结巴分词的缺点_Python 结巴分词
- Java中的frontcolor_front的用法总结大全
- 考研二战上岸985的经验教训分享
- 生活娱乐 360安全卫士和QQ大战
- 的欧美HTML游戏,国外十大HTML5、JavaScript 3D游戏引擎和框架
- Pygame学习笔记 4 —— 时间与运动
- 解决Angular里的报错:ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError()
热门文章
- virtualbox php mac,mac一体机通过Oracle VM VirtualBox装win8.1系统
- mysql动态配置数据源_Spring整合Mybatis实现动态数据源切换教程配置
- ue4导入倾斜摄影_干货 | 6款倾斜摄影裸眼3D采集软件推荐给大家
- 【译】Effective TensorFlow Chapter10——在TensorFlow中利用多GPU处理并行数据
- eclipse怎么导入maven项目 eclipse导入maven项目详细教程
- 04Hadoop中的setPartitionerClass/SortComparator/GroupingComparator问题
- springboot 添加 jsp支持
- 通过 pxe(网络安装)完成centos 系统的网络安装
- SSAS系列——【08】多维数据(程序展现Cube)
- NSubstitute完全手册(一)入门基础