学了一下扩展欧拉定理,不会证,记了个结论,笔记的话,随便去网上搜一搜吧.
-bzoj3884:上帝与集合的正确用法
无脑板子题额

#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long LL;
inline int Pow(int x,int y,int P){
    int ret=1;
    while(y){
        if(y&1)ret=(LL)ret*x%P;
        x=(LL)x*x%P,y>>=1;
    }
    return ret;
}
inline int Phi(int x){
    if(x==1)return 1;
    int i,ret=x;
    for(i=2;i*i<=x;++i)
        if(x%i==0){
            ret=ret/i*(i-1);
            while(x%i==0)x/=i;
        }
    if(x!=1)ret=ret/x*(x-1);
    return ret;
}
inline int Power(int P){
    if(P==1)return 0;
    int phi=Phi(P);
    return Pow(2,Power(phi)+phi,P);
}
int main(){
    int T,P;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&P);
        printf("%d\n",Power(P));
    }
    return 0;
}
Kod

相关文章:

  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
  • 2021-10-06
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2022-01-09
猜你喜欢
  • 2021-08-31
  • 2021-08-02
  • 2021-11-09
  • 2022-12-23
  • 2021-07-13
相关资源
相似解决方案