题意:

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. Jmeter+Jenkins 搭配进行接口测试

    单纯通过Jmeter的界面进行Web的接口测试,效率低下.为此将Jmeter的接口测试与Jenkins联合,实现持续集成.配置完成后,只需修改运行的Jmeter脚本即可,运行结束后测试结果发送到指定邮 ...

  2. 【转】ArcGIS ADF 实时轨迹问题初步解决方案

    Web ADF 实时轨迹是指在Web客户端指定一资源项,并对资源项进行实进跟踪并绘制出轨迹图.实时绘制可采用Ajax实现服务端与客户端无刷新动态绘制,在.net2.0 框架下可轻易实现:通过客户端时钟 ...

  3. winds消息大全

    本文链接:https://blog.csdn.net/testcs_dn/article/details/42360547 消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如, ...

  4. Java Data类

    Date类的概述 java.util,Date 表示日期和时间的类类 Date 表示特定的瞬间,精确到千分之一秒(毫秒) 获取时间原点到当前系统时间经历了多少秒 // 时间原点:1970 年 01 月 ...

  5. vs推送git失败,修改git下config的Log

    一开始写完程序套推送到Git中,然后就来了一下,下面的异常: 异常1 发布到远程存储库时遇到错误: Git failed with a fatal error. fatal: HttpRequestE ...

  6. Android栈溢出漏洞利用练习

    在Github上看到一个Linux系统上的栈溢出漏洞利用练习项目: easy-linux-pwn.在原项目基础上,我稍微做了一些改动,将这个项目移植到了Android 9.0系统上: easy-and ...

  7. 实战_Spring_Cloud

    目录 前言 开发环境 源码地址 创建工程 服务注册中心(Eureka) Eureka Server Eureka Client 注册中心高可用 小结 负载均衡(Ribbon) RestTemplate ...

  8. Nhibernate的Session和StatelessSession性能比较

    Nhibernate的Session和StatelessSession性能比较 作者:Jesai 一个月入30K的大神有一天跟我说:我当年在你现在这个阶段,还在吊儿郎当呢!所以你努力吧! 有时候,一个 ...

  9. ORM 效率补充

    1.only  defer only: 获取数据表中某列或多列的值,注意获取的是对象,如果查询字段不是括号内的,效率反而变低 defer: 获取除了某列或某几列的数据,注意获取的是对象 User.ob ...

  10. map转URL

    package com.psm.util; import java.util.Map; public class MapSwitchUrl { public static String getUrlP ...