#P10005. [集训队互测 2023] 基础寄术练习题

[集训队互测 2023] 基础寄术练习题

Problem Description

For a sequence aa of length nn, define f(a)=1i=knsif(a)=\dfrac{1}{\prod\limits_{i=k}^n s_i}, where sis_i is the prefix sum array of {an}\{a_n\}, and kk is a given constant with 1k21\le k\le 2.

Consider all sequences aa that satisfy the following three conditions:

  • The length of aa is nn.
  • i,j\forall i,j, aiaja_i\ne a_j.
  • 1aim1\le a_i\le m.

Find the sum of f(a)f(a) over all such sequences. Output the answer modulo pp. It is guaranteed that pp is a prime.

Input Format

The first line contains four integers n,m,k,pn,m,k,p, representing the sequence length, the upper bound of the sequence elements, and the modulus.

Output Format

Output one integer: the answer modulo pp.

2 3 2 1000000007
966666675
3 5 2 998244353
148276980
6 10 2 1004535809
622165218
15 20 2 1064822107
53789887
30 40 1 265371653
179937201

Hint

For all testdata, it is guaranteed that 2nm1002\le n\le m\le 100, 108<p<1.07×10910^8<p<1.07\times 10^9, and pp is a prime, and 1k21\le k\le 2.

  • Subtask 1 (10 pts): m20m\le 20.
  • Subtask 2 (25 pts): k=1k=1.
  • Subtask 3 (15 pts): n=m30n=m\le 30.
  • Subtask 4 (10 pts): m30m\le 30.
  • Subtask 5 (15 pts): m40m\le 40.
  • Subtask 6 (10 pts): m70m\le 70.
  • Subtask 7 (15 pts): m100m\le 100.

Translated by ChatGPT 5