N, P = map(int, input().split()) mod = 998244353 cnt = 0 p = P while N // p: cnt += N // p p *= P print(pow(P, cnt, mod))