MOD = 998244353 n, p = map(int, input().split()) if n == 0: print(0) exit() # Precompute factorial and inverse factorial max_n = n fact = [1] * (max_n + 1) for i in range(1, max_n + 1): fact[i] = fact[i-1] * i % MOD inv_fact = [1] * (max_n + 1) inv_fact[max_n] = pow(fact[max_n], MOD-2, MOD) for i in range(max_n-1, -1, -1): inv_fact[i] = inv_fact[i+1] * (i+1) % MOD m_max = n // p # Precompute pow_p and inv_pow_p pow_p = [1] * (m_max + 1) for i in range(1, m_max + 1): pow_p[i] = pow_p[i-1] * p % MOD inv_pow_p = [1] * (m_max + 1) for i in range(0, m_max + 1): inv_pow_p[i] = pow(pow_p[i], MOD-2, MOD) if i != 0 else 1 total = 0 for m in range(0, m_max + 1): s = n - m * p if s < 0: continue term = fact[n] term = term * inv_fact[s] % MOD term = term * inv_fact[m] % MOD term = term * inv_pow_p[m] % MOD total = (total + term) % MOD ans = (fact[n] - total + MOD) % MOD print(ans)