using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static long NN => long.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, p) = (c[0], c[1]); var mul = 0L; var tmp = p; var mod = 998_244_353; checked { while (true) { if (tmp > n) break; // mul = (mul + n / tmp) % mod; mul += n / tmp; tmp *= p; } } WriteLine(Exp((int)p, (int)(mul % mod), mod)); } static long Exp(int n, int k, int mod) { if (k == 0) return 1; if (k == 1) return n % mod; var half = Exp(n, k / 2, mod); var result = (half * half) % mod; return ((k % 2) == 0) ? result : ((result * n) % mod); } }