luogu#P5389. [Cnoi2019] 数学课

[Cnoi2019] 数学课

Problem Description

The smart Cirno started learning calculations, so she happily computed the sum from 11 up to nn.

She obtained an nn-term sequence: {an=1+2+3+4+...+n}\{ a_n = 1 + 2 + 3 + 4 + ... + n \}.

To check whether her calculation is wrong, she needs to pick two elements v1,v2v_1, v_2 from the sequence according to some rule (the two elements may be the same), and then uniformly choose integers a[1,v1]a \in [ 1, v_1 ] and b[1,v2]b \in [ 1, v_2 ] to compare which one is larger.

So, she needs you to compute the probability that a>ba > b.

The rule: The probability of selecting the ii-th element of the sequence is:

$$\frac{a_i}{\sum\limits_{j=1}^n a_j}=\frac{3i\times(i+1)}{n(n+1)(n+2)}$$

Input Format

Input a positive integer nn.

Output Format

Output the probability modulo 998244353998244353.

2
686292993

Hint

For the first 5%5\% of the testdata, n=3n = 3.

For the first 15%15\% of the testdata, n100n \le 100.

For the first 30%30\% of the testdata, n5000n \le 5000.

For the first 55%55\% of the testdata, n107n \le 10^7.

For the first 95%95\% of the testdata, 1n10181 \le n \le 10^{18}, and neither nn nor n+2n+2 is a multiple of 998244353998244353.

For the last 5%5\% of the testdata, n=0n = 0 means nn is positive infinity.

Translated by ChatGPT 5