luogu#P5081. Tweetuzki 爱取球

Tweetuzki 爱取球

Background

This problem is an adaptation that got called out… afraid of getting blasted.

Problem Description

Tweetuzki has a bag with NN indistinguishable balls. Each time, Tweetuzki randomly draws one ball and then puts it back. Find the expected number of draws needed to have drawn every ball at least once.

“Having drawn all balls” means that every ball in the bag has been drawn at least once.

Input Format

One line with one integer NN (1N107)(1 \le N \le 10^7).

Output Format

Output one integer on one line, representing the expected number of draws. Since this number may be very large, output it modulo 2004031320040313 (a prime).

1
1
2
3
3
10020162

Hint

Sample Explanation 1

Drawing one ball the first time is enough to have drawn all balls.

Sample Explanation 2

The probability of having drawn all balls in two draws is 12\frac{1}{2}, in three draws is 14\frac{1}{4}, in four draws is 18\frac{1}{8}, …, and in kk draws is 12k1\frac{1}{2^{k-1}}. Therefore:

$$E(2) = \frac{2}{2} + \frac{3}{4} + \frac{4}{8} + \frac{5}{16} + \cdots = 3$$

Sample Explanation 3

By experiments and calculation, we get:

E(3)=112E(3) = \frac{11}{2}

After taking modulo 2004031320040313, the answer is 1002016210020162.

Constraints

For 30%30\% of the testdata, N5N \le 5.
For 70%70\% of the testdata, N105N \le 10^5.
For 100%100\% of the testdata, 1N1071 \le N \le 10^7.

Translated by ChatGPT 5