0分悬关求调
  • 板块P5175 数列
  • 楼主chenchh210
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/8/19 11:54
  • 上次更新2024/8/19 14:47:04
查看原帖
0分悬关求调
1044185
chenchh210楼主2024/8/19 11:54

代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
struct Matrix{
	int z[5][5];
}s,ans;
const int mod=1e9+7;
int k,f1,f2,p,q,t;
Matrix operator*(const Matrix &x,const Matrix &y){
	Matrix tmp;
	for(int i=1;i<=4;++i)for(int j=1;j<=4;++j)tmp.z[i][j]=0;
	for(int i=1;i<=4;++i)for(int j=1;j<=4;++j)for(int k=1;k<=4;++k)tmp.z[i][j]=(tmp.z[i][j]+x.z[i][k]*y.z[k][j]%mod)%mod;
	return tmp;
}
void pow(int z){
	while(z){
		if(z&1)ans=ans*s;
		s=s*s;
		z>>=1;
	}
	return;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--){
		cin>>k>>f1>>f2>>p>>q;
		if(k==1){
			cout<<f1*f1%mod;
			continue;
		}
		for(int i=1;i<=4;++i)for(int j=1;j<=4;++j)s.z[i][j]=ans.z[i][j]=0;
		ans.z[1][1]=f1*f1%mod,ans.z[1][2]=f2*f2%mod,ans.z[1][3]=f1*f1%mod,ans.z[1][2]=f1*f2%mod;
		s.z[1][1]=s.z[2][1]=s.z[2][3]=1,s.z[2][2]=p*p%mod,s.z[3][2]=q*q%mod,s.z[4][2]=p*q%mod*2%mod,s.z[2][4]=p,s.z[4][4]=q;
		pow(k-1);
		cout<<ans.z[1][1]<<endl;
	}
	return 0;
}
2024/8/19 11:54
加载中...