#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 pp of [1,n][1,n], define its “generated graph” as follows: the graph has nn vertices, and for all 1in1\le i\le n, the undirected edge (i,pi)(i,p_i) exists, and only these edges exist.

Given nn, find how many permutations of [1,n][1,n] have a generated graph with exactly an even number of cycles (self-loops are also counted).

Input Format

One integer nn.

Output Format

One integer, the answer modulo 998244353998244353.

3
3
114514
430461019

Hint

Explanation for Sample 11

These permutations satisfy the condition:

{1,3,2}\{1,3,2\} {2,1,3}\{2,1,3\} {3,2,1}\{3,2,1\}

Constraints

For 20%20\% of the testdata, n10n\le 10.
For 50%50\% of the testdata, n500n\le 500.
For 100%100\% of the testdata, 1n1061\le n\le 10^6.

Translated by ChatGPT 5