zoukankan      html  css  js  c++  java
  • Luogu_P4139 上帝与集合的正确用法 扩展欧拉定理

    Luogu_P4139 上帝与集合的正确用法

    扩展欧拉定理


    题目链接
    扩展欧拉定理如下:

    那这道题
    (2^{2^{2^{dots}}}mod p)
    就是
    (2^{(2^{2^{dots}}mod varphi(p))+varphi(p)}mod p)
    就可以递归求解了
    (p=1)就返回(0)


    代码如下:

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int maxp=1e7;
    int phi[maxp+10];
    inline ll sm(ll x,ll y,ll mod){
        ll res=0;
        while(y){
            if(y&1) res=(res+x)%mod;
            x=(x+x)%mod;y>>=1;
        }
        return res;
    }
    inline ll qp(ll x,ll y,ll mod){
        ll res=1;
        while(y){
            if(y&1) res=sm(res,x,mod)%mod;
            x=sm(x,x,mod)%mod;y>>=1;
        }
        return res;
    }
    inline ll sl(ll x){
        if(x==1) return 0;
        return qp(2,sl(phi[x])+phi[x],x);
    }
    int t,p;
    int main()
    {
        for(int i=2;i<=maxp;i++) phi[i]=i;
        for(int i=2;i<=maxp;i++)
            if(phi[i]==i) for(int j=i;j<=maxp;j+=i)
                phi[j]=phi[j]/i*(i-1);
        scanf("%d",&t);
        while(t--){
            scanf("%d",&p);printf("%lld
    ",sl((ll)p));
        }
        return 0;
    }
    
  • 相关阅读:
    Win7 安装
    线上java排查
    spring boot
    redisson
    Jcaptca 图片
    URL重写
    gradle导出依赖的jar包
    Redis tomcat
    flex 通过htmlservices链接moss的rest(rest 的get post方式)
    java语言MySQL批处理
  • 原文地址:https://www.cnblogs.com/ChrisKKK/p/11696848.html
Copyright © 2011-2022 走看看