RE求助
查看原帖
RE求助
1262406
yhy2024楼主2024/11/27 12:56

rt

#include<bits/stdc++.h>
#define N 11000005
#define ll long long
using namespace std;
int mod,T,cnt;
int phi[N],p[700000];
bool vis[N];
int init(){
	phi[1]=1;
	for(int i=2;i<=N-5;i++)
	{
		if(!vis[i]){
			phi[i]=i-1;
			p[++cnt]=i;
		}
		for(int j=1;j<=cnt&&i*p[j]<=N-5;j++){
			vis[i*p[j]]=1;
			if(i%p[j]==0){
				phi[i*p[j]]=phi[i]*p[j];
				break;
			}
			else{
				phi[i*p[j]]=phi[i]*phi[p[j]];		
			}
		}
	}
}
ll Pow(ll a,ll b,ll mod){
	if(b==0){
		return 1;
	} 
	if(b==1){
		return a%mod;
	}
	ll t=Pow(a,b/2,mod)%mod;
	if(b%2==0){
		return t*t%mod;
	}
	else{
		return (t*t%mod)*(a%mod)%mod;
	}
}
int solve(int mod){
	if(mod==1) return 0;
	else return Pow(2,solve(phi[mod])+phi[mod],mod);
}
int main(){
	init();
	ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--){
		cin>>mod;
		cout<<solve(mod)<<'\n';
	} 
	return 0;
}
2024/11/27 12:56
加载中...