#P11253. Factorial and Power Series Modulo Calculation
Factorial and Power Series Modulo Calculation
Factorial and Power Series Modulo Calculation
Moon is a primary school student who encountered the following problem in his homework. Given two positive integers (n) and (k), compute the value of
[ S = \sum_{i=1}^{n} \frac{i!}{i^{k}}, ]
where (i!) denotes the factorial of (i) (i.e. (i! = 1\times2\times3\times\cdots\times i)). Since Moon has only learned integer arithmetic and not real number operations, you are required to help him by computing (S) modulo (998244353). In other words, if (S) can be expressed in its simplest form as the fraction (\frac{p}{q}), output
[ p \times q^{-1} \bmod 998244353, ]
where (q^{-1}) is the modular inverse of (q) modulo (998244353) (it is guaranteed that (q^{-1}) exists under the given modulus).
inputFormat
The input consists of a single line containing two space‐separated positive integers: (n) and (k).
outputFormat
Output a single integer representing the value of (S) modulo (998244353).
sample
3 1
4