• HDU


    Declare:
    k=∑ i=φ(in) mod 1000000007 k=∑i=1mφ(i∗n) mod 1000000007

    n is a square-free number.

    φ φ is the Euler's totient function.

    find:
    ans=..k      mod ans=kkkk...k mod p

    There are infinite number of k

    InputMultiple test cases(test cases 100 ≤100 ), one line per case.

    Each line contains three integers, n,n,m and p .

    1n,m,p10 7  1≤n,m,p≤107
    OutputFor each case, output a single line with one integer, ans.Sample Input

    1 2 6
    1 100 9

    Sample Output

    4
    7

    题意:k=∑ φ(i∗n)%1000000007;求K^(K^(K^....))%P;

    思路:第二部分用欧拉降幂一层一层的降。第一部分可以看这里。

    就是左边部分 φ(p)=p-1,但是有的部分由于没有i含有p因数,实际是p而不是p-1,所以要把这部分加进去,所以就有了右边部分。  

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int maxn=10000010;
    int phi[maxn],p[maxn],vis[maxn],cnt;
    vector<int>G[maxn];
    void prime()
    {
        phi[1]=1; for(int i=2;i<maxn;i++){
            if(!vis[i]) p[++cnt]=i,phi[i]=i-1;
            for(int j=1;j<=cnt&&p[j]*i<maxn;j++){
                vis[p[j]*i]=1; phi[i*p[j]]=phi[i]*phi[p[j]];
                if(i%p[j]==0){ phi[i*p[j]]=phi[i]*p[j]; break;}
            }
        }
    }
    int qpow(int a,int x,int P){
        int res=1; while(x){
            if(x&1) res=(ll)res*a%P;
            a=(ll)a*a%P; x>>=1;
        } return res;
    }
    int get(int K,int P)
    {
        if(P==1) return 0;
        return qpow(K,get(K,phi[P])+phi[P],P);
    }
    int main()
    {
        prime();
        int P,ans,T;
        scanf("%d",&T);
        while(T--){
            scanf("%d",&P);
            ans=get(2,P);
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    js控制表格隔行变色
    浅谈css的伪元素::after和::before
    CSS 背景色变化 结构化伪类的练习
    css清除浮动的几种方式,哪种最合适?
    怎么去检测浏览器支不支持html5和css3?
    display:flex 布局详解(2)
    css3弹性盒子display:flex
    Referer和空Referer
    不要懒惰,坚持每周总结一篇博客
    比较2个文件的不同处
  • 原文地址:https://www.cnblogs.com/hua-dong/p/9844115.html
Copyright © 2020-2023  润新知