代码(50pts也可以认为是10pts)希望大佬帮忙改正,蟹蟹:
#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353;
int t,n;
long long A,B,X,Y;
long long ans;
long long POW(long long x,int y)
{
long long aaa=1;
while(y)
{
if(y&1) aaa=(aaa*x%MOD+MOD)%MOD;
x=(x*x%MOD+MOD)%MOD;
y>>=1;
}
return aaa;
}
int main()
{
cin>>t;
while(t--)
{
ans=1;
scanf("%d%lld%lld%lld%lld",&n,&A,&B,&X,&Y);
long long f1,f2;
for(int i=1;i<=n;i++)
{
bool fg=0;
if(i==1)
f1=A,f2=X;
else if(i==2)
{
f1=B,f2=Y;
B=A,Y=X;
}
else
{
A=floor(sqrtl((long double)(f1*B)))+1,X=floor(sqrtl((long double)(f2*Y)))+1;
B=f1,Y=f2;
f1=A,f2=X;
if((f1==B&&f2==Y)||(f1==B+1&&f2==Y+1)||(f1==B&&f2==Y+1)||(f1==B+1&&f2==Y)) fg=1;
}
if(n<=100) fg=0;
if(fg)
{
int z=n-i+1,x=f2-f1,y=Y-B;
if((f1==B&&f2==Y)||(f1==B+1&&f2==Y+1))
{
// cout<<"*"<<" ";
ans=(ans*POW(x,z)%MOD+MOD)%MOD;
}
else
{
// cout<<"/"<<" ";
if(z%2==1)
{
ans=(ans*x%MOD+MOD)%MOD;
}
z/=2;
ans=(ans*POW(x*y,z)%MOD+MOD)%MOD;
}
// cout<<f1<<" "<<f2<<endl;
break;
}
ans=((ans*(f2-f1))%MOD+MOD)%MOD;
// cout<<f1<<" "<<f2<<endl;
}
ans=(ans+MOD)%MOD;
printf("%lld\n",ans);
}
return 0;
}