{"problem":{"name":"「ALFR Round 1」D 小山的元力","description":{"content":"小山有 $n$ 个相同的元素，他想将这 $n$ 个元素分为 $m$ 堆，显然有很多种分法。对于每种分法，定义 $a_i$ 为第 $i$ 堆的元素数量，$b_i=i!\\times a_i$（其中 $i!$ 表示 $i$ 的阶乘），以及 $c=\\sum\\limits_{i=1}^mb_i$。而小山的元力为所有分法的 $c$ 值之和。小山想知道他的元力是多少，由于答案可能很大，所以最终答案应对 $p$ ","description_type":"Markdown"},"platform":"Luogu","limit":{"time_limit":2000,"memory_limit":524288},"difficulty":{"LuoguStyle":"P4"},"is_remote":true,"is_sync":true,"sync_url":null,"sign":"LGP10380"},"statements":[{"statement_type":"Markdown","content":"小山有 $n$ 个相同的元素，他想将这 $n$ 个元素分为 $m$ 堆，显然有很多种分法。对于每种分法，定义 $a_i$ 为第 $i$ 堆的元素数量，$b_i=i!\\times a_i$（其中 $i!$ 表示 $i$ 的阶乘），以及 $c=\\sum\\limits_{i=1}^mb_i$。而小山的元力为所有分法的 $c$ 值之和。小山想知道他的元力是多少，由于答案可能很大，所以最终答案应对 $p$ 取模（保证 $p$ 为质数）。\n\n## Input\n\n一行三个整数 $n,m,p$，含义见**题目描述**。\n\n## Output\n\n一个数表示小山的元力。\n\n[samples]\n\n## Note\n\n### 样例解释\n\n将 $3$ 个元素分为 $2$ 堆的方案为：\n\n1. `0 3`\n2. `1 2`\n3. `2 1`\n4. `3 0`\n\n小山的元力为：$(1!\\times0+2!\\times3)+(1!\\times1+2!\\times2)+(1!\\times2+2!\\times1)+(1!\\times3+2!\\times0)=18$。\n\n### 数据范围\n| 子任务 | 分值 | 限制 |\n| :----------: | :----------: | :----------: |\n| $0$ | $20$ | $n,m\\le5$ |\n| $1$ | $80$ | - |\n\n对于 $100\\%$ 的数据，$1\\le n,m\\le10^6$，$1\\le p\\le10^7$。","is_translate":false,"language":"English"}],"meta":{"iden":"LGP10380","tags":["O2优化"],"sample_group":[["3 2 37","18"]],"created_at":"2026-03-03 11:09:25"}}