시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 (추가 시간 없음) | 256 MB | 5 | 5 | 4 | 100.000% |
We call a simple graph good if each component of the graph has at most one cycle.
Your task is to count the number of edges belonging to one cycle for all the good graphs with $n$ labeled vertices.
In order to avoid calculations of huge integers, report the sum of the number of edges modulo $p$ instead.
There are multiple test cases. The first line of the input contains two integers $T$ and $p$ ($1 \le T \le 3000$, $1 \le p \le 2^{30}$), indicating the number of test cases and the modulus. For each test case:
The first line contains the only integer $n$ ($1 \leq n \leq 3000$).
For each test case, output the sum of the numbers of edges modulo $p$ in one line.
7 998244353 1 2 3 4 5 6 7
0 0 3 60 1050 19380 393750
There are three types of good graphs having four labeled vertices in which cycles exist.
The numbers of these graphs are $3$, $12$ and $4$ respectively. Consequently, the sum of the numbers of edges is $3 \times 4 + 12 \times 3 + 4 \times 3 = 60$.