没过样例求助
  • 板块P5175 数列
  • 楼主seanlsy
  • 当前回复4
  • 已保存回复4
  • 发布时间2022/6/20 22:06
  • 上次更新2023/10/27 22:54:27
查看原帖
没过样例求助
674247
seanlsy楼主2022/6/20 22:06

rt

#include <bits/stdc++.h>
using namespace std;
#define int __int128
#define mod 1000000007
inline int read(){
	int x=0;bool f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?x:-x;
}
inline void out(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) out(x/10);
	putchar(x%10|48);
}
int t,n,a1,a2,x,y;
struct jz{
    int a[4][4];
}base,xx;
inline jz mul(jz x,jz y){
    jz z;
    memset(z.a,0,sizeof(z.a));
    for(int k=0;k<4;k++)
        for(int i=0;i<4;i++)
            for(int j=0;j<4;j++)
                z.a[i][j]+=(x.a[i][k]*y.a[k][j]%mod),z.a[i][j]%=mod;
    return z;
}
inline jz Pow(jz x,int y){
    jz res=x;
    for(y--;y;x=mul(x,x),y>>=1)
        if(y&1)
            res=mul(res,x);
    return res;
}
signed main(){
	t=read();
	while(t--){
		n=read(),a1=read(),a2=read(),x=read(),y=read();
		if(n==1){
			out(a1*a1%mod),putchar(10);
			continue;
		}
		memset(base.a,0,sizeof(base.a));
		memset(xx.a,0,sizeof(xx.a));
		base.a[0][0]=base.a[0][2]=a1*a1%mod,
		base.a[0][1]=a2*a2%mod,
		base.a[0][3]=a1*a2%mod,
		xx.a[0][0]=xx.a[0][1]=xx.a[2][1]=1,
		xx.a[1][1]=x*x%mod,xx.a[1][2]=y*y%mod,
		xx.a[1][3]=2*x*y%mod,xx.a[3][1]=x,xx.a[3][3]=y;
		base=mul(Pow(xx,n-1),base);
		out(base.a[0][0]),putchar(10);
	}
	return 0;
}
2022/6/20 22:06
加载中...