AtCoder TOYOTA SYSTEMS Programming Contest 2021(AtCoder Beginner Contest 228) E - Integer Sequence F


 思路:

 对于从K个数中选取长度为N的序列,每一个数都有N个选择,所以总共有K的N次选择,每次选择又有M个数可以选择,所以有M的K的N次选择,由于K的N次过大,不可直接用快速幂,所以采用欧拉降幂,具体推导如图:

   顺便放个欧拉降幂公式:

 代码:

#include 
#define ll long long

using namespace std;

typedef pair PII;

const int N = 3e5 + 10, mod = 998244353;

ll n, k, m;

ll qmi(ll a, ll b, ll p)
{
    ll ret = 1, base = a % p;
    while(b)
    {
        if(b & 1) ret = ret * base % p;
        base = base * base % p;
        b >>= 1;
    }

    return ret % p;
}

void solve()
{
    cin >> n >> k >> m;

    if(m % mod == 0)
        cout << 0 << endl;
    else 
    {
        ll num = qmi(k, n, mod - 1);
        ll ans = qmi(m, num, mod);
        cout << ans << endl;
    }

}

int main()
{
    ios::sync_with_stdio(0);
    //int T;
    //cin >> T;
    //while(T --)
    //{
        solve();
    //}
    return 0;
}