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里是不变的,可以数论分块,再在每一段里用矩阵快速幂
debug了一下午。。
坑点:
1.数论分块的写法要注意,已更新
2.矩阵乘法在赋值回去的时候记得模一下
3.矩阵相乘不可逆,注意看一下
代码:
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> #include<stack> #include<queue> #include<deque> #include<set> #include<vector> #include<map> #include<functional>#define fst first #define sc second #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) #define lson l,mid,root<<1 #define rson mid+1,r,root<<1|1 #define lc root<<1 #define rc root<<1|1 #define lowbit(x) ((x)&(-x)) using namespace std;typedef double db; typedef long double ldb; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> PI; typedef pair<ll,ll> PLL;const db eps = 1e-6; const int mod = 1e9+7; const int maxn = 2e6+100; const int maxm = 2e6+100; const int inf = 0x3f3f3f3f; const db pi = acos(-1.0); void prt(ll b[4][4]){for(int i = 1; i <= 3; i++){for(int j = 1; j <= 3; j++){printf("%3I64d ", b[i][j]);}printf("\n");}return; } void mtpl(ll a[4][4], ll b[4][4], ll s[4][4]){ll tmp[4][4];mem(tmp, 0);for(int i = 1; i <= 3; i++){for(int j = 1; j <= 3; j++){for(int k = 1; k <= 3; k++){tmp[i][j] += (a[i][k]*b[k][j])%mod;}}}for(int i = 1; i <= 3; i++){for(int j = 1; j <= 3; j++){s[i][j] = tmp[i][j]%mod;}}return; }ll a, b, c, d, p, n; ll B[4][4]; void fp(ll n, ll tmp){ll A[4][4];mem(A, 0);A[1][1] = d;A[1][2] = c;A[2][1] = 1;A[1][3] = tmp;A[3][3] = 1;//prt(A);while(n){if(n&1) mtpl(A,B,B);mtpl(A,A,A);n>>=1;}return; } int main() {int T;scanf("%d",&T);while(T--){scanf("%I64d %I64d %I64d %I64d %I64d %I64d", &a, &b, &c, &d, &p, &n);if(n==1){printf("%I64d\n", a);continue;}if(n==2){printf("%I64d\n", b);continue;}mem(B, 0);for(int i = 1; i <= 3; i++)B[i][i]=1;B[1][1] = b;B[2][1] = a;B[3][1] = 1;ll l , r;for(l = 3, r = 0; l <= n; l = r + 1){if(p/l) r = min(p, p/(p/l));else r = n;ll tmp = p/l;fp(r-l+1,tmp);}printf("%I64d\n", B[1][1]);}return 0; } /* 4 1 2 1 2 5 3 1 2 1 2 3 5 1 2 3 4 7 4 2 3 3 3 3 4*/
转载于:https://www.cnblogs.com/wrjlinkkkkkk/p/9484799.html
HDU6395 Sequence(矩阵快速幂+数论分块)相关推荐
- HDU - 5667 Sequence(矩阵快速幂+费马小定理降幂)
题目链接:点击查看 题目大意:给出函数f(x): 现给出n,a,b,c,mod,求f(n)对mod取模后的结果 题目分析:这个题目相对于前几个题来说稍微加大了点难度,但还是挺水的一个题,首先我们可以对 ...
- Codeforces 1106F Lunar New Year and a Recursive Sequence 矩阵快速幂,原根转化模意义下对数,BSGS
文章目录 题意 题解 对数法转指数线性递推 原根与模意义下求对数 拔山盖世! 最终步骤 Problem Origin 狠搞了一个多星期,做出来之后仍然一知半解,写个博客重理思路. 题意 定义序列fff ...
- CodeForces 392C Yet Another Number Sequence 矩阵快速幂
题意: \(F_n\)为斐波那契数列,\(F_1=1,F_2=2\). 给定一个\(k\),定义数列\(A_i=F_i \cdot i^k\). 求\(A_1+A_2+ \cdots + A_n\). ...
- Recursive sequence(矩阵快速幂)
这就是矩阵的魅力吗,爱了爱了 题 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<iostream> #i ...
- 数学--数论--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 ...
- hdu 6395Sequence【矩阵快速幂】【分块】
Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total ...
- poj2778DNA Sequence (AC自动机+矩阵快速幂)
转载请注明出处: http://www.cnblogs.com/fraud/ --by fraud DNA Sequence Time Limit: 1000MS Memory ...
- HDU 5950 Recursive sequence(矩阵快速幂)
题目链接:Recursive sequence 题意:给出前两项和递推式,求第n项的值. 题解:递推式为:$F[i]=F[i-1]+2*f[i-2]+i^4$ 主要问题是$i^4$处理,容易想到用矩阵 ...
- UVA10689 Yet another Number Sequence【数列+矩阵快速幂】
Let's define another number sequence, given by the following function: f(0) = a f(1) = b f(n) = f(n ...
最新文章
- 俄罗斯“木船”机器人系统将于2020年部署部队
- Partition Tables介绍及分区表转换
- 【信息安全】职业发展之惑系列之二 --- 怎样的心态才有助于职业发展
- Windows从命令行创建文本文件的两种方式
- 27.CSS3文本效果
- HTTP协议基础知识总结
- 配置phython环境
- SpringBoot————JPA快速使用
- 前端如何更精准的评估开发时间
- 深入浅出JavaScript (五) 详解Document.write()方法
- 如何鉴别项目经理/软件设计师的水平
- 华为魔术2手机拆机图解_荣耀Magic2手机内部做工如何?荣耀Magic2手机拆机
- Java基础学习(1)-反射
- github action自动部署构建入门
- python timepicker_基于react开发的时间选择组件(TimePicker)
- java 刽子手游戏_Java刽子手游戏重绘()无法正常工作
- 基于PHP的学生量化管理系统
- 计算机网络常见面试题目
- Log4j2 日志 依赖 jar包 缺失 导致启动报错 解决方法
- win7设置定时锁定计算机,Windows7电脑屏幕如何设置不自动锁屏
热门文章
- AndroidM 内核空间到用户空间接口类型
- nginx配置:支持phpfastcgi,nginx和php-cgi通信,部分nginx常量解释
- 八、spring生命周期之BeanPostProcessor
- An end-to-end TextSpotter with Explicit Alignment and Attention
- 生成html报告并整合自动发动邮件功能
- JavaScript函数补完:toString()
- WinDbg配置与下载 (转载)
- IE6、7 a链接内图片加滤镜后导致a标签链接失效问题解决
- 同一个世界不同的人(转)
- Elementui动态换肤