zoukankan      html  css  js  c++  java
  • 2019ICPC南京网络赛B super_log(a的b塔次方)

    https://nanti.jisuanke.com/t/41299

    分析:题目给出a,b,mod求满足条件的最小a,由题目的式子得,每次只要能递归下去,b就会+1,所以就可以认为b其实是次数,什么的次数?对数函数的反函数。。。。即题目求a的a次方的a次方.....一直搞b次后求得的答案。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int M=1e6+6;
    ll ph[M];
    ll init(){
        ph[0]=0,ph[1]=1;
        for(int i=2;i<M;i++)
            ph[i]=i;
        for(int i=2;i<M;i++){
            if(ph[i]==i){
                for(int j=i;j<M;j+=i)
                    ph[j]=ph[j]/i*(i-1);
            }
        }
    }
    ll ksm(ll a,ll b,ll mod){
        ll t=1ll;
        while(b){
            if(b&1)
                t=(t*a)%mod;
            b>>=1;
            a=(a*a)%mod;
        }
        return t;
    }
    ll dfs(ll a,ll b,ll p){
        if(b==0)
            return 1;
        if(p==1)
            return 0;
        ll P=dfs(a,b-1,ph[p]);
        if(P<ph[p]&&P)
            return ksm(a,P,p);
        return ksm(a,P+ph[p],p);
    }
    int main(){
        int t;
        scanf("%d",&t);
        init();
        while(t--){
            ll a,b,mod;
            scanf("%lld%lld%lld",&a,&b,&mod);
            printf("%lld
    ",dfs(a,b,mod)%mod);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    开启Spring Boot 之旅
    Java笔试面试练习题---集合
    Python
    Python
    Redis -下载与基本使用
    Git
    Vue全家桶-Vue-router&Vuex
    Es6
    Vue-前端
    Django基础及实战
  • 原文地址:https://www.cnblogs.com/starve/p/11448266.html
Copyright © 2011-2022 走看看