首页 技术 正文
技术 2022年11月15日
0 收藏 338 点赞 3,955 浏览 1821 个字

Maybe ACMers of HIT are always fond of fibonacci numbers, because it is so beautiful. Don’t you think so? At the same time,fishcanfly always likes to change and this time he thinks about the following series of numbers which you can guess is derived from the definition of fibonacci number.

The definition of fibonacci number is:

f(0) = 0, f(1) = 1, and for n>=2, f(n) = f(n – 1) + f(n – 2)

We define the new series of numbers as below:

f(0) = a, f(1) = b, and for n>=2, f(n) = p*f(n – 1) + q*f(n – 2),where p and q are integers.

Just like the last time, we are interested in the sum of this series from the s-th element to the e-th element, that is, to calculate fibonacci数列的和取余(2).””””

Great!Let’s go!

Input

The first line of the input file contains a single integer t (1 <= t <= 30), the number of test cases, followed by the input data for each test case.

Each test case contains 6 integers a,b,p,q,s,e as concerned above. We know that -1000 <= a,b <= 1000,-10 <= p,q <= 10 and 0 <= s <= e <= 2147483647.

Output

One line for each test case, containing a single interger denoting S MOD (10^7) in the range [0,10^7) and the leading zeros should not be printed.

Sample Input

2
0 1 1 -1 0 3
0 1 1 1 2 3

Sample Output

2
3
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const long long mod=1e7;typedef struct
{
long long m[3][3];
}mat;mat I={1,0,0,0,1,0,0,0,1};mat calc(mat a,mat b) //矩阵相乘计算
{
int i,j,k;
mat c;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
c.m[i][j]=0;
for(k=0;k<3;k++)
{
c.m[i][j]+=(a.m[i][k]*b.m[k][j]+mod)%mod;
}
c.m[i][j]=(c.m[i][j]+mod)%mod;
}
return c;
}mat matirx(mat P,long long n) //矩阵快速幂(二分法)
{
mat m=P,b=I;
while(n>=1)
{
if(n&1) b=calc(b,m);
n>>=1;
m=calc(m,m);
}
return b;
}int main()
{
int t,a,b,p,q;
long long s,e,sum;
cin>>t;
while(t--)
{
sum=0;
scanf("%d%d%d%d%lld%lld",&a,&b,&p,&q,&s,&e);
mat x,y,P={p,q,0,1,0,0,1,0,1}; //p,q由输入决定,不能在全局定义mat P
y=matirx(P,e);
sum=(b*y.m[2][0]+a*y.m[2][1]+a*y.m[2][2])%mod;
sum=(sum+mod)%mod;
if(s>1)
{
x=matirx(P,s-1);
sum=sum-(b*x.m[2][0]+a*x.m[2][1]+a*x.m[2][2])%mod;
sum=(sum+mod)%mod;
}
else if(s==1)
sum-=a;
sum=(sum+mod)%mod;
printf("%lld\n",sum);
}
return 0;
}

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,905
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,430
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,247
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,058
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,690
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,727