#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int mod=10000000;
struct mat
{
long long t[3][3];
void set()
{
memset(t,0,sizeof(t));
}
} a,b; mat multiple(mat a,mat b,int n,int p)
{
int i,j,k;
mat temp;
temp.set();
for(i=0; i<n; i++)
for(j=0; j<n; j++)
{
//if(a.t[i][j]!=0)
for(k=0; k<n; k++)
temp.t[i][k]=(temp.t[i][k]+a.t[i][j]*b.t[j][k]+p)%p;
}
return temp;
} mat quick_mod(mat b,int n,int m,int p)
{
mat t;
t.set();
for(int i=0;i<n;i++) t.t[i][i]=1;
while(m)
{
if(m&1)
{
t=multiple(t,b,n,p);
}
m>>=1;
b=multiple(b,b,n,p);
}
return t;
} void init(int p,int q)
{
b.set();
b.t[0][0]=1;
b.t[1][2]=q;
b.t[2][0]=1;
b.t[2][1]=1;
b.t[2][2]=p;
}
int main()
{
int A,B,p,q,s,e,t;
cin>>t;
while(t--)
{
cin>>A>>B>>p>>q>>s>>e;
long long l,r;
s--;
if(s<0) l=0;
else if(s==0) l=A;
else if(s==1) l=B+A;
else {
init(p,q);
a=quick_mod(b,3,s,mod);
l=((A*a.t[0][0]+A*a.t[1][0]+B*a.t[2][0])%mod+mod)%mod;
}
if(e==0) r=A;
else if(e==1) r=B+A;
else {
init(p,q);
a=quick_mod(b,3,e,mod);
r=((A*a.t[0][0]+A*a.t[1][0]+B*a.t[2][0])%mod+mod)%mod;
}
cout<<(r-l+mod)%mod<<endl;
}
return 0;
}

HIT 2255 Not Fibonacci(矩阵高速幂)的更多相关文章

  1. HDU1588-Gauss Fibonacci(矩阵高速幂+等比数列二分求和)

    题目链接 题意:g(x) = k * x + b.f(x) 为Fibonacci数列.求f(g(x)),从x = 1到n的数字之和sum.并对m取模. 思路:  设A = |(1, 1),(1, 0) ...

  2. HDU 1588 Gauss Fibonacci(矩阵高速幂+二分等比序列求和)

    HDU 1588 Gauss Fibonacci(矩阵高速幂+二分等比序列求和) ACM 题目地址:HDU 1588 Gauss Fibonacci 题意:  g(i)=k*i+b;i为变量.  给出 ...

  3. hdu 3306 Another kind of Fibonacci(矩阵高速幂)

    Another kind of Fibonacci                                                        Time Limit: 3000/10 ...

  4. UVA10518 - How Many Calls?(矩阵高速幂)

    UVA10518 - How Many Calls?(矩阵高速幂) 题目链接 题目大意:给你fibonacci数列怎么求的.然后问你求f(n) = f(n - 1) + f(n - 2)须要多少次调用 ...

  5. HDU 2254 奥运(矩阵高速幂+二分等比序列求和)

    HDU 2254 奥运(矩阵高速幂+二分等比序列求和) ACM 题目地址:HDU 2254 奥运 题意:  中问题不解释. 分析:  依据floyd的算法,矩阵的k次方表示这个矩阵走了k步.  所以k ...

  6. UVA 11551 - Experienced Endeavour(矩阵高速幂)

    UVA 11551 - Experienced Endeavour 题目链接 题意:给定一列数,每一个数相应一个变换.变换为原先数列一些位置相加起来的和,问r次变换后的序列是多少 思路:矩阵高速幂,要 ...

  7. HDU2842-Chinese Rings(递推+矩阵高速幂)

    pid=2842">题目链接 题意:求出最少步骤解出九连环. 取出第k个的条件是,k-2个已被取出,k-1个仍在支架上. 思路:想必九连环都玩过吧,事实上最少步骤就是从最后一个环開始. ...

  8. HDU2276 - Kiki &amp; Little Kiki 2(矩阵高速幂)

    pid=2276">题目链接 题意:有n盏灯.编号从1到n.他们绕成一圈,也就是说.1号灯的左边是n号灯.假设在第t秒的时候,某盏灯左边的灯是亮着的,那么就在第t+1秒的时候改变这盏灯 ...

  9. uva 10655 - Contemplation! Algebra(矩阵高速幂)

    题目连接:uva 10655 - Contemplation! Algebra 题目大意:输入非负整数,p.q,n,求an+bn的值,当中a和b满足a+b=p,ab=q,注意a和b不一定是实数. 解题 ...

  10. hdu 3221 Brute-force Algorithm(高速幂取模,矩阵高速幂求fib)

    http://acm.hdu.edu.cn/showproblem.php?pid=3221 一晚上搞出来这么一道题..Mark. 给出这么一个程序.问funny函数调用了多少次. 我们定义数组为所求 ...

随机推荐

  1. [细节版]Let'sEncrypt 免费通配符/泛域名SSL证书添加使用教程

    参考网址:https://lnmp.org/faq/letsencrypt-wildcard-ssl.html 使用的dns服务商:阿里云 , 更多服务商地址可见参考网址. 遇见的问题一. [Sat ...

  2. [备忘]js-xlsx 操作 Excel 插件

    github地址:https://github.com/SheetJS/js-xlsx oss地址:http://oss.sheetjs.com/js-xlsx/xlsx.full.min.js

  3. PKU 2184 Cow Exhibition 01背包

    题意: 有一些牛,每头牛有一个Si值,一个Fi值,选出一些牛,使得max( sum(Si+Fi) ) 并且 sum(Si)>=0, sum(Fi)>=0 思路: 随便选一维做容量(比如Fi ...

  4. 【codeforces 335A】Banana

    [题目链接]:http://codeforces.com/contest/335/problem/A [题意] 让你构造一个长度为n的字符串; 每次你可以从这个字符串中任意取走字符; 让你求出取的次数 ...

  5. 成都磨子桥技工学校 / 2016届练习区 0003:jubeeeeeat

    0003:jubeeeeeat 总时间限制:  1000ms 内存限制:  256000kB 描述 众所周知,LZF很喜欢打一个叫Jubeat的游戏.这是个音乐游戏,游戏界面是4×4的方阵,会根据音乐 ...

  6. &lt;转&gt;Openstack ceilometer 宿主机监控模块扩展

    <Openstack ceilometer监控项扩展>( http://eccp.csdb.cn/blog/?p=352 )主要介绍了对虚拟机监控项扩展, 比較简单.怎样在ceilomet ...

  7. cocos2d-x 粒子效果

    大规模运动的物体通常有两种方法实现 1.使用帧动画来模拟 2,粒子效果 粒子系统有CCParticleSystem类实现,CCParticleSystem实现了对粒子的控制与调度,对粒子的操作包含: ...

  8. 与Greenplum度过的三个星期

    5月4日-5月24日.断断续续折腾了三个星期的Greenplum,总算告一段落了:扩容,发现扩不成容.仅仅好升级.升级,发现一堆错误,仅仅好暂停修复数据库:修好了,继续升级.升完级,发现错误.修啊修啊 ...

  9. light oj 1317

    Description You probably have played the game "Throwing Balls into the Basket". It is a si ...

  10. poj_1195Mobile phones,二维树状数组

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...