from collections import * import heapq import bisect INF = float("inf") MOD = 998244353 N, P = map(int, input().split()) e = 0 while N: e += N // P N //= P print(pow(P, e, MOD))