#P10380. 「ALFR Round 1」D 小山的元力

「ALFR Round 1」D 小山的元力

Problem Description

Xiaoshan has nn identical elements. He wants to divide these nn elements into mm piles. Obviously, there are many ways to do this. For each division, let aia_i be the number of elements in the ii-th pile, bi=i!×aib_i=i!\times a_i (where i!i! denotes the factorial of ii), and c=i=1mbic=\sum\limits_{i=1}^m b_i. Xiaoshan's elemental power is defined as the sum of the values of cc over all divisions. Xiaoshan wants to know what his elemental power is. Since the answer may be very large, output the final answer modulo pp (it is guaranteed that pp is a prime number).

Input Format

One line with three integers n,m,pn, m, p, with meanings given in the Description.

Output Format

Output one number representing Xiaoshan's elemental power.

3 2 37
18

Hint

Sample Explanation

The ways to divide 33 elements into 22 piles are:

  1. 0 3
  2. 1 2
  3. 2 1
  4. 3 0

Xiaoshan's elemental power is: $(1!\times0+2!\times3)+(1!\times1+2!\times2)+(1!\times2+2!\times1)+(1!\times3+2!\times0)=18$.

Constraints

Subtask Score Constraints
00 2020 n,m5n,m\le5
11 8080 -

For 100%100\% of the testdata, 1n,m1061\le n,m\le10^6, 1p1071\le p\le10^7.

Translated by ChatGPT 5