luogu#P8307. 〈 TREEのOI 2022 Spring 〉Absolutely Simple Game

〈 TREEのOI 2022 Spring 〉Absolutely Simple Game

Background

rin and len are playing an absolutely simple game, and pcq is the referee.

Problem Description

Initially, the range [l,r]=[1,n][l,r]=[1,n] is given. pcq uniformly randomly selects a natural number tt from it. Then rin and len take turns to operate, with rin moving first.

On each turn, the current player guesses an integer x[l,r]x\in[l,r]. If x=tx=t, the game ends and the current player loses. If x<tx<t, update the range [l,r][l,r] to [x+1,r][x+1,r]. If x>tx>t, update the range [l,r][l,r] to [l,x1][l,x-1].

Both rin and len fully understand the rules and are extremely cute and smart (they will both maximize their own winning probability). During the game, everyone knows all information on the table except tt. Find rin's winning probability.

Input Format

One line with one integer nn.

Output Format

One line with one integer, representing rin's winning probability, output the fraction mod 998244353\bmod~998244353.

3
665496236

Hint

Sample Explanation 1:

rin's winning probability is 23\dfrac 23 (guess 22 at the beginning). After taking mod 998244353\bmod~998244353, the output is 665496236665496236.


This problem uses bundled SubTask testing.

SubTask ID Score Special Constraints
00 1010 n0 (mod2)n\equiv 0\ \pmod 2
11 2020 n100n\le 100
22 3030 n109n\le 10^9
33 4040 n1018n\le 10^{18}

For 100%100\% of the testdata, 1n10181 \le n\le 10^{18}.


How to take a rational number modulo?

xymodm\dfrac {x}{y} \bmod m is defined as xym2mod mxy^{m-2}\bmod~m.

mm must be a prime.

It is guaranteed that, after reducing the fraction, the denominator is not a multiple of 998244353998244353.

Translated by ChatGPT 5