#P4463. [集训队互测 2012] calc

    ID: 3393 远端评测题 3000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp数学2012WC/CTSC/集训队生成函数

[集训队互测 2012] calc

Description

A sequence a1,a2,,ana_1, a_2, \dots, a_n is valid if and only if:

  • a1,a2,,ana_1, a_2, \dots, a_n are all integers in [1,k][1, k].
  • a1,a2,,ana_1, a_2, \dots, a_n are pairwise distinct.

The value of a sequence is defined as the product of all its numbers, i.e., a1×a2××ana_1\times a_2\times\dots\times a_n.

Compute the sum of the values of all distinct valid sequences, modulo pp. Two sequences are different if and only if they differ at any position.

Input Format

One line with three positive integers k,n,pk, n, p, as described above.

Output Format

One line with the result.

9 7 10007
3611

Hint

Constraints

For 5%5\% of the testdata, k10k \le 10, n10n \le 10.

For 20%20\% of the testdata, k1000k \le 1000, n20n \le 20.

For 50%50\% of the testdata, k109k \le 10^9, n20n \le 20.

For 100%100\% of the testdata, k109k \le 10^9, n500n \le 500, p109p \le 10^9, it is guaranteed that pp is prime and n+1<k<pn + 1 < k < p.

by WJMZBMR


iostream\mathsf i \color{red}\mathsf{ostream} thinks the testdata for this problem is too weak, so he made a harder version.

Translated by ChatGPT 5