最新 代码

#include<bits/stdc++.h>
#define pb push_back
#define en '\n'
#define bi bitset<maxn>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<sstream>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
#define ull unsigned long long
#define ll long long
//const ull mod=1e9+7;
const ull maxn=2e5+5;
const ull inf=0x3f3f3f3f;
template <class T> void rd( T &x){
x=0;
T f=1;
char s;
s=getchar();
while(!isdigit(s)){
        if(s=='-')f=-1;
    s=getchar();
}
while(isdigit(s)){
    x=x*10+s-'0';
    s=getchar();
}
x*=f;
}

ll trie[maxn][26];
ll tot;
ll cnt[maxn];
ll  ed[maxn];
void insert(char *str){
ll len=strlen(str),p=1;
for(ll k=0;k<len;k++){
    ll ch=str[k]-'a';
    if(trie[p][ch]==0)trie[p][ch]=++tot;
    p=trie[p][ch];
    ed[p]+=1;
}
//ed[p]=1;
}
ll  ask(char  *str){
ll len=strlen(str);
ll p=1;
//string res="";
for(ll k=0;k<len;k++){
   // if(trie[p][str[k]-'a']==0)return 0;
    p=trie[p][str[k]-'a'];
    //res+=str[k];
    if(ed[p]==1){
        return k;
    }
}
//return ed[p];
}
char s[1005][25];
ll run(ll &x,ll p){
    ll res=0;
    while(x%p==0){
    res+=1;
    x/=p;
    }return res;
}

ll n,p;
void rep(ll &x,ll pp){
x%=pp;
x+=pp;
x%=pp;
}
ll mul(ll a,ll b, ll mod){
ll res=0;
a%=mod;
while(b){
    if(b&1)
        res=(res+a)%mod;
        a=(a+a)%mod;
        b>>=1;
}
return res%mod;
}


ll pow_m(ll a,ll  b){
ll res=1;
while(b){
    if(b&1){
        res=mul(res,a,n);//res*a;
        rep(res,n);
    }
    b>>=1;
    a=mul(a,a,n);//a*a;
    rep(a,n);
}
return res;
}
bool isp(ll x){
ll tt=sqrt(x*1.0);
for(ll i=2;i*i<=x;i++){
    if(x%i==0)return 0;
}
return 1;
}

signed main(){
	#ifdef local
    freopen("input.txt", "r", stdin);
#endif
//getchar();
ll T;
cin>>T;
    while(T--){
        rd(n);
    ll tem;
    for(ll i=n-1;i;--i){
        if(isp(i)){
           tem=i;
           break;
        }
    }
    ll res=1;
    for(ll i=tem+1;i<=n-1;i++){
            res=mul(res,i,n);//(res%n)*(i%n);
            rep(res,n);
    }
     ll ans=mul(n-1,pow_m(res,n-2),n);//(n-1)*pow_m(res,n-2);
    rep(ans,n);
    cout<<ans<<en;
    }
	return 0;
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值