Permutation 2

AtCoder
IDfps_24_l
Time2000ms
Memory256MB
Difficulty
You are given an integer $N$. Consider permutations $p = (p_1, p_2, \dots, p_N)$ of $(1, 2, \dots, N)$. Count how many such permutations satisfy the following condition, and output the result modulo $998244353$. * For every integer $i$ such that $1 \leq i \leq N$, it must hold that $p_{p_i} \neq i$. ## Constraints * $1 \leq N \leq 2.5 \times 10^5$ * $N$ is an integer ## Input The input is given from standard input in the following format: $N$ [samples]
Samples
Input #1
3
Output #1
2

The following $2$ permutations $p$ satisfy the condition:

*   $(2,3,1)$
*   $(3,1,2)$
Input #2
123456
Output #2
916370671
API Response (JSON)
{
  "problem": {
    "name": "Permutation 2",
    "description": {
      "content": "You are given an integer $N$.   Consider permutations $p = (p_1, p_2, \\dots, p_N)$ of $(1, 2, \\dots, N)$.   Count how many such permutations satisfy the following condition, and output the result modu",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "fps_24_l"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an integer $N$.  \nConsider permutations $p = (p_1, p_2, \\dots, p_N)$ of $(1, 2, \\dots, N)$.  \nCount how many such permutations satisfy the following condition, and output the result modu...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments