#P11253. [GDKOI2023 普及组] 小学生数学题

[GDKOI2023 普及组] 小学生数学题

Problem Description

Moon is an elementary school student. While doing homework, he encountered the following problem: given positive integers n,kn, k, find the value of the expression:

i=1ni!ik\sum_{i=1}^n \frac{i!}{i^k}

Here, i!i! denotes the factorial of ii, that is, i!=1×2×3×4×ii! = 1 \times 2 \times 3 \times 4 \ldots \times i. This expression is too hard, so Moon hopes to get your help. However, since Moon has only learned integer operations and has not learned real-number operations, he wants you to help him compute the value of this expression modulo 998244353998244353. That is, if the final result can be simplified into an irreducible fraction pq\frac{p}{q}, you only need to output p×q1mod998244353p \times q^{-1} \bmod 998244353, where q1q^{-1} is the modular inverse of qq modulo 998244353998244353.

Input Format

The first line contains two integers n,kn, k.

Output Format

One line with one integer, representing the answer modulo 998244353998244353.

5 1 
34
100 100
523011929
10000000 10000000
686183373

Hint

Sample Explanation

In sample 11, since i!i=(i1)!\frac{i!}{i} = (i - 1)!, the original expression is equivalent to i=15(i1)!=34\sum_{i=1}^5 (i - 1)! = 34.

Constraints

For all testdata, 1n,k2×1071 \le n, k \le 2 \times 10^7.

For 30%30\% of the testdata, k=1k = 1.

For another 30%30\% of the testdata, 1k31 \le k \le 3.

Translated by ChatGPT 5