Problem 4D Yuezheng Ling and Random Tree

Problem 4D Yuezheng Ling and Random Tree

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem 4D Yuezheng Ling and Random Tree

Time Limit: 2s
Memory Limit: 256MB

Background

image-20230510105120074

Statement

Yuezheng Ling and Luo Tianyi are two friends who love studying algorithms.

Yuezheng Ling gives Luo Tianyi a tree with \(n\) nodes, rooted at \(1\). The tree is generated according to the following algorithm:

  1. For each node \(i\) in the range \([2, n]\), select a random node \(j\) from the range \([1, i-1]\)
  2. add an edge between node \(i\) and node \(j\)

Luo Tianyi is fascinated by the tree and wants to find out the expected value of the average depth of all the nodes in the generated tree, modulo 998244353. In other words, if \(D(i)\) denotes the depth of node \(i\), then the expected value of the average depth of all the nodes is \(E(\frac{\sum_{i=1}^n D(i)}n)\)

Note that the depth of the root is considered to be \(0\).

Input

The input consists of a single integer n, the number of nodes in the tree.

Output

Output a single line containing the expected value of the average depth of all the nodes in the tree, modulo 998244353.

We can prove that the expected value is always rational. Additionally, under the constraints of this problem, when that value is represented as \(\frac QP\) with two coprime integers \(P\) and \(Q\), there is a unique integer \(R\) such that \(R\times Q\equiv P\pmod {998244353}\) and \(0≤R<998244353\). Find this \(R\).

Sample Input 1

3

Sample Output 1

831870295

Explanation 1

The expected value is \(\frac{5}{6}\)。

Constrains

For 60% of the test cases, \(1 \le n \le 10\).

For all test cases, \(1 \le n \le 10^5\).

悬赏令第四周

未参加
状态
已结束
规则
OI
题目
4
开始于
2023-05-14 18:30
结束于
2023-05-21 00:00
持续时间
149.5 小时
主持人
参赛人数
42