AC代码:
#include<iostream>
#include<memory.h>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<list>
#include<map>
#include<algorithm>
typedef long long LL;
const LL maxn = 1000+10;
const LL mod =10000000;
using namespace std;
struct matrix
{
LL m[3][3];
};
matrix A;
matrix I={
1,0,0,
0,1,0,
0,0,1
};
matrix multi(matrix a,matrix b)
{
matrix c;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++){
c.m[i][j]=0;
for(int k=0;k<3;k++){
c.m[i][j]+=a.m[i][k]*b.m[k][j]%mod;
}
c.m[i][j]%=mod;
}
return c;
}
matrix power(matrix A,LL k)
{
matrix ans=I,p=A;
while(k){
if(k&1){
ans=multi(ans,p);
k--;
}
k>>=1;
p=multi(p,p);
}
return ans;
}
int main()
{
int t,a,b,p,q,s,e;
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d%d%d",&a,&b,&p,&q,&s,&e);
A.m[0][0]=1;A.m[0][1]=p;A.m[0][2]=q;
A.m[1][0]=0;A.m[1][1]=p;A.m[1][2]=q;
A.m[2][0]=0;A.m[2][1]=1;A.m[2][2]=0;
s--;
int s1,s2;
if(s<0) s1=0;
else if(s==0) s1=a;
else{
matrix ans=power(A,s-1);
s1=(ans.m[0][0]%mod*(a+b)%mod+ans.m[0][1]%mod*b%mod+ans.m[0][2]%mod*a%mod)%mod;
}
if(e==0) s2=a;
else{
matrix ans=power(A,e-1);
s2=(ans.m[0][0]%mod*(a+b)%mod+ans.m[0][1]%mod*b%mod+ans.m[0][2]%mod*a%mod)%mod;
}
LL l=((s2-s1)%mod+mod)%mod;
cout<<l<<endl;
}
return 0;
}