zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    python-全局变量是否使用global总结
    python-多线程创建以及查看
    python-tcp客户端
    python-udp聊天器
    python-udp接受数据
    python-udp发送数据
    python-正则表达式总结
    JAVA程序员面试必知32个知识点
    计算机专业英语基础篇
    非常经典有深度的电影英文台词
  • 原文地址:https://www.cnblogs.com/hua-dong/p/9844115.html
Copyright © 2011-2022 走看看