P29140 [洛谷] [POI 2021/2022 R1] Card Arrangement
省选
题目描述

Problem Description

We sort a permutation in increasing order using the following method:

One operation: Denote the first number as $k$. Find $k-1$ in the permutation (if $k=1$, take $n$ instead), and move $k-1$ to the first position of the permutation, shifting the intermediate numbers one position to the right.

The value of one operation: The original position of $k-1$ (or $n$) in the permutation (numbered starting from 0).

The value of a permutation: The sum of the values of each operation until the permutation is sorted.

Given $n$ and $m$, find the sum of the values of all $n!$ permutations, modulo $m$.

Input Format

One line containing two positive integers, $n$ and $m$.

Output Format

One line containing one integer, the answer modulo $m$.

Sample Input and Output

Input Sample #1

2 100

Output Sample #1

1

Input Sample #2

3 100

Output Sample #2

15

Input Sample #3

10 1000

Output Sample #3

100

Input Sample #4

500 100000

Output Sample #4

60000

Input Sample #5

100000 1000

Output Sample #5

0

Notes

For all data, $2 \leq n \leq 1000000$, $2 \leq m \leq 10^9$.

Subtask Number Additional Constraints Score
1 $n \leq 10$ 10
2 $n \leq 2000$ 60
3 None 30
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 100
样例输出
1