题意:输入n,k,m ,求 (m^k^n取模于P)
解法:费马小定理,得
m^k^n(mod P)=m^(k^n(mod P-1))(mod P)
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll;
ll mo = 998244353;
ll qmi(ll x,ll k) {
ll res = 1;
x %= mo;
while (k) {
if (k & 1)res *= x,res%=mo;
x *= x; x %= mo;
k >>= 1;
}
return res;
}
ll qmi1(ll x, ll k) {
ll moo = mo - 1;
ll res = 1;
x %= moo;
while (k) {
if (k & 1)res *= x, res %= moo;
x *= x; x %= moo;
k >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k, m; cin >> n >> k >> m;
if (m % mo == 0) {
cout << 0 << endl; return 0;
}
ll kk = qmi1(k, n);
//cout << kk << endl;
kk = qmi(m, kk);
cout << kk << endl;
return 0;
}