Codeforces Global Round 6
G
Permutation Concatenation
Codeforces
3300
原题
← FH →
翻译中…

Let $n$ be an integer. Consider all permutations on integers $1$ to $n$ in lexicographic order, and concatenate them into one big sequence $P$. For example, if $n = 3$, then $P = [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]$. The length of this sequence is $n \cdot n!$.

翻译中…

Let $1 \leq i \leq j \leq n \cdot n!$ be a pair of indices. We call the sequence $(P_i, P_{i+1}, \dots, P_{j-1}, P_j)$ a subarray of $P$.

翻译中…

You are given $n$. Find the number of distinct subarrays of $P$. Since this number may be large, output it modulo $998244353$ (a prime number).

翻译中…

Input

翻译中…

The only line contains one integer $n$ ($1 \leq n \leq 10^6$), as described in the problem statement.

翻译中…

Output

翻译中…

Output a single integer — the number of distinct subarrays, modulo $998244353$.

翻译中…

Note

翻译中…

In the first example, the sequence $P = [1, 2, 2, 1]$. It has eight distinct subarrays: $[1]$, $[2]$, $[1, 2]$, $[2, 1]$, $[2, 2]$, $[1, 2, 2]$, $[2, 2, 1]$ and $[1, 2, 2, 1]$.

翻译中…

样例

Input #1
2
Output #1
8
InputCopy OutputCopy
Input #2
10
Output #2
19210869
InputCopy OutputCopy
题目信息
题号
1266G
时间限制
1 s
内存限制
256 MB
标签
后缀结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。