atcoder#AGC034F. [AGC034F] RNG and XOR
[AGC034F] RNG and XOR
Score : points
Problem Statement
Snuke found a random number generator. It generates an integer between and (inclusive). An integer sequence represents the probability that each of these integers is generated. The integer () is generated with probability , where . The process of generating an integer is done independently each time the generator is executed.
Snuke has an integer , which is now . He can perform the following operation any number of times:
- Generate an integer with the generator and replace with , where denotes the bitwise XOR.
For each integer (), find the expected number of operations until becomes , and print it modulo . More formally, represent the expected number of operations as an irreducible fraction . Then, there exists a unique integer such that $R \times Q \equiv P \mod 998244353,\ 0 \leq R < 998244353$, so print this .
We can prove that, for every , the expected number of operations until becomes is a finite rational number, and its integer representation modulo can be defined.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line () should contain the expected number of operations until becomes , modulo .
2
1 1 1 1
0
4
4
4
after zero operations, so the expected number of operations until becomes is .
Also, from any state, the value of after one operation is , , or with equal probability. Thus, the expected numbers of operations until becomes , and are all .
2
1 2 1 2
0
499122180
4
499122180
The expected numbers of operations until becomes , , and are , , and , respectively.
4
337 780 799 10 796 875 331 223 941 67 148 483 390 565 116 355
0
468683018
635850749
96019779
657074071
24757563
745107950
665159588
551278361
143136064
557841197
185790407
988018173
247117461
129098626
789682908