求助
查看原帖
求助
160839
Prean楼主2020/5/31 12:57

用getchar发现不行,用了scanf结果TLE。。。

求助QAQ

#include<cstdio>
#include<cctype>
typedef long long ll;
ll a,b,m,t,phi,ans=1;bool flag;
inline ll read(){
    char s;ll n=0;
    while(!isdigit(s=getchar()));
    while(n=n*10+(s^48),isdigit(s=getchar()));
    return n;
}
signed main(void){
    int i;char s;
    a=read();phi=m=t=read();
    for(i=2;i*i<=t;++i)if(!(t%i)){
        phi-=phi/i;
        while(!(t%i))t/=i;
    }
    if(t>1)phi-=phi/t;
    while(scanf("%c",&s)!=EOF){
        if((b=b*10+(s^48))>=phi){
            flag=true;
            b%=phi;
        }
    }
    if(flag)b+=phi;
    for(a%=m;b;b>>=1,a=a*a%m)if(b&1)ans=ans*a%m;
    printf("%lld",ans);
}
2020/5/31 12:57
加载中...