题目链接

 #include<bits/stdc++.h>
using namespace std;
#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;} ll A,B,C,D,N,P;
struct mat {
ll a[][];
}c; mat mat_mul(mat x,mat y) {
mat s;
mem(s.a,);
for(int i=;i<;i++)
for(int j=;j<;j++)
for(int k=;k<;k++)
s.a[i][j]=(s.a[i][j]+x.a[i][k]*y.a[k][j]%mod)%mod;
return s;
} mat mat_pow(ll n) {
mat res;
mem(res.a,);
res.a[][]=res.a[][]=res.a[][]=;
while(n) {
if(n&) res=mat_mul(res,c);
c=mat_mul(c,c);
n>>=;
}
return res;
} ll solove(ll i) {
ll l=i,r=N;
ll p=P/i;
while(l<r) {
int mid=r-(r-l)/;
if(p==P/mid) l=mid;
else if(p>P/mid)r=mid-;
else l=mid+;
}
return l;
} int main() {
int T;scanf("%d",&T);
while(T--) {
scanf("%lld%lld%lld%lld%lld%lld",&A,&B,&C,&D,&P,&N);
if(N==){printf("%lld\n",A);continue;}
if(N==){printf("%lld\n",B);continue;}
ll f1=B; ll f2=A; mat ans;
for(ll i=; i<=N;) {
ll j=solove(i);
mem(c.a,);
c.a[][]=D;c.a[][]=C;
c.a[][]=;c.a[][]=;
c.a[][]=P/i; ans=mat_pow(j-i+);
ll ff1=(ans.a[][]*f1%mod+ans.a[][]*f2%mod+ans.a[][])%mod;
ll ff2=(ans.a[][]*f1%mod+ans.a[][]*f2%mod+ans.a[][])%mod;
f1=ff1; f2=ff2; i=j+;
}
printf("%lld\n",f1);
}
return ;
}

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

  1. [hdu-6395]Sequence 分块+矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6395 因为题目数据范围太大,又存在递推关系,用矩阵快速幂来加快递推. 每一项递推时  加的下取整的数随 ...

  2. 杭电多校第七场 1010 Sequence(除法分块+矩阵快速幂)

    Sequence Problem Description Let us define a sequence as below f1=A f2=B fn=C*fn-2+D*fn-1+[p/n] Your ...

  3. HDU-6395 多校7 Sequence(除法分块+矩阵快速幂)

    Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  4. HDU - 6395 Sequence (整除分块+矩阵快速幂)

    定义数列: $\left\{\begin{eqnarray*} F_1 &=& A \\ F_2 &=& B \\ F_n &=& C\cdot{}F_ ...

  5. A - Number Sequence(矩阵快速幂或者找周期)

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

  6. HDU 5950 Recursive sequence(矩阵快速幂)

    题目链接:Recursive sequence 题意:给出前两项和递推式,求第n项的值. 题解:递推式为:$F[i]=F[i-1]+2*f[i-2]+i^4$ 主要问题是$i^4$处理,容易想到用矩阵 ...

  7. HDU 5667 Sequence(矩阵快速幂)

    Problem Description Holion August will eat every thing he has found. Now there are many foods,but he ...

  8. HDU 6395 Sequence 【矩阵快速幂 && 暴力】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others)   ...

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

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

随机推荐

  1. 继续学习C:运算符

     " / "  两整数相除,结果为整数,有一方是实数形式,结果保留小数         " % "  求余运算符要求两侧均为整型数据, 数值取余,符号与被除数一 ...

  2. ACM学习历程—HDU4415 Assassin’s Creed(贪心)

    Problem Description Ezio Auditore is a great master as an assassin. Now he has prowled in the enemie ...

  3. ACM学习历程—FZU2148 Moon Game(计算几何)

    Moon Game Description Fat brother and Maze are playing a kind of special (hentai) game in the clearl ...

  4. P2056 采花

    题目描述 萧芸斓是 Z国的公主,平时的一大爱好是采花. 今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花.花园足够大,容纳了 n 朵花,花有 c 种颜色(用整数 1-c 表示) ,且花是排成 ...

  5. bzoj 1941 [Sdoi2010]Hide and Seek——KDtree

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1941 第二道KDtree! 枚举每个点,求出距离它的最远和最近距离.O( n * logn ...

  6. C++11中的原子操作(atomic operation)

    所谓的原子操作,取的就是“原子是最小的.不可分割的最小个体”的意义,它表示在多个线程访问同一个全局资源的时候,能够确保所有其他的线程都不在同一时间内访问相同的资源.也就是他确保了在同一时刻只有唯一的线 ...

  7. 【转】 Pro Android学习笔记(五四):调试和分析(2):View层次结构

    目录(?)[-] 帮助性能分析 帮助精简UI设计 对于模拟器上的应用(非真实设备),可以查看Hierarchy View,如下图: 帮助性能分析 当我们选择某个view时,我们可以看到measurin ...

  8. 快速搭建SpringBoot项目

    Spring Boot简介: Spring Boot是Spring社区发布的一个开源项目,旨在帮助开发者快速并且更简单的构建项目.它使用习惯优于配置的理念让你的项目快速运行起来,使用Spring Bo ...

  9. project online get approvals task data 获取审批待办任务接口

    调用接口地址:重要 http://xxxx/sites/pwa/_vti_bin/PSI/ProjectServer.svc Header 三个必要参数: 其中SOAPAction写死就行,如果是on ...

  10. WCF服务用户名密码访问

    有2种方式, 第一直接在程序中指定用户名密码,配置调用 private void BtnSearch_Click(object sender, EventArgs e) { try { var cli ...