1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<stack> #include<map> #include<set> #include<vector> #include<queue> #include<string> #include<cmath> using namespace std; #define ll long long #define rep(i,n) for(int i =0; i < n; ++i) #define CLR(x) memset(x,0,sizeof x) #define MEM(a,b) memset(a,b,sizeof a) #define pr(x) cout << #x << " = " << x << " "; #define prln(x) cout << #x << " = " << x << endl; const int maxn = 1e7+5; const int INF = 0x3f3f3f3f; int phi[maxn], prime[maxn]; const int MOD = 1e9+7; bool vis[maxn]; int pt; ll sum[maxn]; void init(){ int k = 0; pt = 0;
phi[1] = 1; for(int i = 2; i < maxn; ++i){ if(!vis[i]){ phi[i] = i-1; prime[pt++] = i; } for(int j = 0; j < pt ; ++j){ k = prime[j]*i; if(k>=maxn) break; vis[k] = true; if(i%prime[j] == 0){ phi[k] = phi[i] * prime[j]; break; } else{ phi[k] = phi[i] * (prime[j]-1); } } } sum[0] = 0; for(int i = 1; i < maxn; ++i){ sum[i] = (sum[i-1] + phi[i])%MOD; } } ll getans(int n, int m){ if(n == 1) return sum[m]; if(m == 1) return phi[n]; if(m < 1) return 0; for(int i = 0; i < pt; ++i){ if(n%prime[i] == 0){ return ((prime[i]-1)*getans(n/prime[i], m)%MOD + getans(n, m/prime[i]))%MOD; } } } ll ret(ll x, ll y, int p){ ll ans = 1; x%=p; while(y){ if(y&1)ans = ans*x%p; x = x*x%p; y >>= 1; } return ans; } ll getpow(ll k, int p){ if(p == 1) return 0; ll tmp = getpow(k, phi[p]); return ret(k, tmp+phi[p], p); } int main(){ #ifdef LOCAL freopen("/home/zeroxf/桌面/in.txt","r",stdin); #endif init(); int n, m, p; while(scanf("%d%d%d", &n, &m, &p) != EOF){ ll k = getans(n,m); printf("%lld\n",getpow(k,p)); } return 0; }
|