#P8143. [JRKSJ R4] Stirling
[JRKSJ R4] Stirling
Background
A possibly useless hint:
$$f(n)=\sum_{i=0}^n \begin{Bmatrix} n\\i\end{Bmatrix}g(i) \leftrightarrow g(n)=\sum_{i=0}^n (-1)^{n-i} \begin{bmatrix} n\\i\end{bmatrix} f(i)$$Problem Description
For a permutation of , define its “generated graph” as follows: the graph has vertices, and for all , the undirected edge exists, and only these edges exist.
Given , find how many permutations of have a generated graph with exactly an even number of cycles (self-loops are also counted).
Input Format
One integer .
Output Format
One integer, the answer modulo .
3
3
114514
430461019
Hint
Explanation for Sample
These permutations satisfy the condition:
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5