n, p = map(int, input().split()) mod = 998244353 e = 0 current = p while current <= n: e += n // current current *= p print(pow(p, e, mod))