题意:

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-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);
void prt(ll b[][]){
for(int i = ; i <= ; i++){
for(int j = ; j <= ; j++){
printf("%3I64d ", b[i][j]);
}
printf("\n");
}
return;
}
void mtpl(ll a[][], ll b[][], ll s[][]){
ll tmp[][];
mem(tmp, );
for(int i = ; i <= ; i++){
for(int j = ; j <= ; j++){ for(int k = ; k <= ; k++){
tmp[i][j] += (a[i][k]*b[k][j])%mod;
}
}
}
for(int i = ; i <= ; i++){
for(int j = ; j <= ; j++){
s[i][j] = tmp[i][j]%mod;
}
}
return;
}ll a, b, c, d, p, n;
ll B[][];
void fp(ll n, ll tmp){
ll A[][];
mem(A, );
A[][] = d;
A[][] = c;
A[][] = ;
A[][] = tmp;
A[][] = ;
//prt(A);
while(n){
if(n&) mtpl(A,B,B);
mtpl(A,A,A);
n>>=;
}
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==){
printf("%I64d\n", a);
continue;
}
if(n==){
printf("%I64d\n", b);
continue;
} mem(B, );
for(int i = ; i <= ; i++)B[i][i]=;
B[][] = b;
B[][] = a;
B[][] = ;
ll l , r;
for(l = , r = ; l <= n; l = r + ){
if(p/l) r = min(p, p/(p/l));
else r = n;
ll tmp = p/l;
fp(r-l+,tmp);
} printf("%I64d\n", B[][]);
}
return ;
}
/*
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 */

HDU6395 Sequence(矩阵快速幂+数论分块)的更多相关文章

  1. hdu6395 (矩阵快速幂+分块)

    Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.Q Hand In Hand Onli ...

  2. HDU5950 Recursive sequence (矩阵快速幂加速递推) (2016ACM/ICPC亚洲赛区沈阳站 Problem C)

    题目链接:传送门 题目: Recursive sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total ...

  3. HDU5950 Recursive sequence —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-5950 Recursive sequence Time Limit: 2000/1000 MS (Java/Others)   ...

  4. hdu-5667 Sequence(矩阵快速幂+费马小定理+快速幂)

    题目链接: Sequence Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) ...

  5. UVA - 10689 Yet another Number Sequence 矩阵快速幂

                      Yet another Number Sequence Let’s define another number sequence, given by the foll ...

  6. HDU6395-Sequence 矩阵快速幂+除法分块 矩阵快速幂模板

    目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门  原题目描述在最下面. Solution ...

  7. Yet Another Number Sequence——[矩阵快速幂]

    Description Everyone knows what the Fibonacci sequence is. This sequence can be defined by the recur ...

  8. HDU 1005 Number Sequence(矩阵快速幂,快速幂模板)

    Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...

  9. HDU - 1005 Number Sequence 矩阵快速幂

    HDU - 1005 Number Sequence Problem Description A number sequence is defined as follows:f(1) = 1, f(2 ...

随机推荐

  1. iOS开发常见问题

    1. 在 ViewController 中添加子视图时,导航栏遮挡添加的子视图 let bpView = BpView.init(frame: CGRect.init(x: , y: , width: ...

  2. AcWing 251. 小Z的袜子| 分块+莫队

    传送门 题目描述 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿. 终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命. 具体来说,小Z把这N只袜子从 ...

  3. 低副瓣阵列天线综合2 matlab HFSS

    接着继续研究阵列天线设计,得到了电流幅度分布或功率分布之后,就可以进行阵列设计或馈电网络设计了,之前利用HFSS仿真过单列的串馈天线,后面会继续复习熟悉一下,本次我找了一篇硕士论文利用威尔金森功分器来 ...

  4. Pandas的介绍与基本使用

    1.什么是Pandas 当大家谈论到数据分析时,提及最多的语言就是Python和SQL,而Python之所以适合做数据分析,就是因为他有很多强大的第三方库来协助,pandas就是其中之一,它是基于Nu ...

  5. 洛谷p1502窗口的星星 扫描线

    题目链接:https://www.luogu.org/problem/P1502 扫描线的板子题,把每个点看成矩形,存下边(x,y,y+h-1,li)和(x+w-1,y,y+h-1),在按横坐标扫线段 ...

  6. 世界上最流行的版本控制系统——Git

    版本控制系统,也就是VCS(Version Control System),可以说是程序员必备的工具.那么它到底是什么,有什么作用呢? 举个例子,如果你想查看你所开发的软件在一个月之前的模样,同时还想 ...

  7. Docker windows nano server容器中安装ssh实现远程登录管理

    [问题] 使用ServiceMonitor.exe作为前台进程运行起来的容器无法attach. 无法远程连接到运行中的容器中进行管理. [解决方法] 在container中新建管理员用户,通过SSH实 ...

  8. GeoGebra学习-lesson1

    我曾经想过学习数学的时候总觉得不太直观,希望通过直观的图形来直观的学习数学.庆幸的是,在B站看视频时看到了妈咪叔使用了这款数学软件,很好用的样子.就去简单的了解了一下,下面是摘抄自<Geogeb ...

  9. Redhat下如何查看nvidia显卡的工作状况

    安装完毕nvidia显卡驱动后,可以使用命令来查看显卡的工作状况,命令如下: nvidia-smi 输入上述命令后,显示界面如下 安装nvidia显卡驱动的步骤,请参照驱动安装cuda和cudnn.

  10. GP工作室——系统设计

    团队作业第二次--系统设计 问题 答案 这个作业属于哪个课程 软件工程 这个作业要求在哪里 作业要求 团队名称 GP工作室 这个作业的目标 对项目软件进行更为详细的系统性设计 按照本游戏的设计要求,我 ...