D - Problem Scores Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 12001200

問題文

コンテストで使う NN 問の問題がジャッジに選ばれ、各問に配点を付ける段階になりました。

問題 ii の配点 AiA_i は、11 以上 NN 以下の整数でなければなりません。 また、すでに問題は難易度順に並んでおり、A1A2ANA_1 \le A_2 \le \ldots \le A_N でなければなりません (複数問の配点が同じになるのは構いませんが)。

ICPC のファンであるあなたは、解いた問題数が多い参加者ほど上位となってほしいと考えています。 この理由から、任意の kk (1kN11 \le k \le N-1) に対して、任意の kk 問の配点の合計が任意の k+1k+1 問の配点の合計より真に小さくなるようにしたい、とあなたは考えています。

このような配点の付け方は何通りあるでしょうか?この数を与えられた素数 MM で割った余りを求めてください。

制約

  • 2N50002 \leq N \leq 5000
  • 9×108<M<1099 \times 10^8 < M < 10^9
  • MM は素数である。
  • 入力中のすべての値は整数である。

入力

入力は以下の形式で標準入力から与えられる。

NN MM

出力

配点の付け方の数を MM で割った余りを出力せよ。


入力例 1Copy

Copy
2 998244353

出力例 1Copy

Copy
3

可能な配点の付け方は (1,1)(1, 1), (1,2)(1, 2), (2,2)(2, 2) です。


入力例 2Copy

Copy
3 998244353

出力例 2Copy

Copy
7

可能な配点の付け方は (1,1,1)(1, 1, 1), (1,2,2)(1, 2, 2), (1,3,3)(1, 3, 3), (2,2,2)(2, 2, 2), (2,2,3)(2, 2, 3), (2,3,3)(2, 3, 3), (3,3,3)(3, 3, 3) です。


入力例 3Copy

Copy
6 966666661

出力例 3Copy

Copy
66

入力例 4Copy

Copy
96 925309799

出力例 4Copy

Copy
83779

Score : 12001200 points

Problem Statement

NN problems have been chosen by the judges, now it's time to assign scores to them!

Problem ii must get an integer score AiA_i between 11 and NN, inclusive. The problems have already been sorted by difficulty: A1A2ANA_1 \le A_2 \le \ldots \le A_N must hold. Different problems can have the same score, though.

Being an ICPC fan, you want contestants who solve more problems to be ranked higher. That's why, for any kk (1kN11 \le k \le N-1), you want the sum of scores of any kk problems to be strictly less than the sum of scores of any k+1k+1 problems.

How many ways to assign scores do you have? Find this number modulo the given prime MM.

Constraints

  • 2N50002 \leq N \leq 5000
  • 9×108<M<1099 \times 10^8 < M < 10^9
  • MM is a prime.
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

NN MM

Output

Print the number of ways to assign scores to the problems, modulo MM.


Sample Input 1Copy

Copy
2 998244353

Sample Output 1Copy

Copy
3

The possible assignments are (1,1)(1, 1), (1,2)(1, 2), (2,2)(2, 2).


Sample Input 2Copy

Copy
3 998244353

Sample Output 2Copy

Copy
7

The possible assignments are (1,1,1)(1, 1, 1), (1,2,2)(1, 2, 2), (1,3,3)(1, 3, 3), (2,2,2)(2, 2, 2), (2,2,3)(2, 2, 3), (2,3,3)(2, 3, 3), (3,3,3)(3, 3, 3).


Sample Input 3Copy

Copy
6 966666661

Sample Output 3Copy

Copy
66

Sample Input 4Copy

Copy
96 925309799

Sample Output 4Copy

Copy
83779


2025-04-05 (Sat)
20:46:16 +00:00