#P2606. [ZJOI2010] 排列计数

    ID: 1619 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp数学2010各省省选浙江组合数学

[ZJOI2010] 排列计数

Description

We call a permutation p1,p2,,pnp_1, p_2, \dots, p_n of 1n1 \sim n "Magic" if and only if

$$\forall i \in [2,n], \; p_i > p_{\lfloor i/2 \rfloor}.$$

Count how many permutations of 1n1 \sim n are "Magic". The answer may be large; output the value modulo mm.

Input Format

One line contains two integers n,mn, m, as described above.

Output Format

Output a single integer: the number of "Magic" permutations of 1n1 \sim n modulo mm.

20 23 
16

Hint

Constraints
For 100%100\% of the data, 1n1061 \le n \le 10^6, 1m1091 \le m \le 10^9, and mm is a prime.

Translated by ChatGPT 5