求助第五个测试点
查看原帖
求助第五个测试点
1121995
2021zjhs005楼主2023/11/17 20:33

请教一下,为什么会 WA on #5?(或许是溢出的问题,但我也不会改)。

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
ull T,mod,i,j,a,b,p,ans,res;
string id;
ull read(ull m){
	ull x=0;bool f=false;
	char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		if(x>=m) {x%=m;f=1;}
		c=getchar();
	}
	if(f) x+=m;
	return x;
}
ull phi(ull k){
	ull sum=k;
	for(j=2;j<=sqrt(k);j++)
		if(k%j==0){
			sum=sum/j*(j-1);
			while(k%j==0) k/=j;
		}
	if(k>=2) return sum/k*(k-1);
	return sum;
}
int main(){
	cin>>id;
	if(id=="1_998244353"){
		mod=998244353;		
		p=998244352;
		cin>>T;
		for(i=1;i<=T;i++){
			b=read(p);res=19;ans=1;
			while(b){
				if(b&1) ans=ans*res%mod;
				res=res*res%mod;
				b>>=1;
			}
			cout<<ans<<endl;		
		}
	}
	else if(id=="1?"){
		mod=1145141;		
		p=1145140;
		cin>>T;
		for(i=1;i<=T;i++){
			b=read(p);res=19;ans=1;
			while(b){
				if(b&1) ans=ans*res%mod;
				res=res*res%mod;
				b>>=1;
			}
			cout<<ans<<endl;	
		}	
	}
	else if(id=="1?+"){
		mod=5211600617818708273;
		p=5211600617818708272;
		cin>>T;
		for(i=1;i<=T;i++){
			b=read(p);res=19;ans=1;
			while(b){
				if(b&1) ans=(ans%mod)*(res%mod)%mod;
				res=(res%mod)*(res%mod)%mod;
				b>>=1;
			}
			cout<<ans<<endl;	
		}		
	}
	return 0;
}
2023/11/17 20:33
加载中...