Walk Alone has a strange random number generator, the pseudocode of which is as follows:
uintk rand(uintk x, int A[]) {
for (int i = 0; i < n; ++i) {
if (A[i] >= 0) x ^= x << A[i];
else x ^= x >> -A[i];
}
return x;
}
Here '
uintk' denotes the type of unsigned integers with
k binary bits, and '
n' denotes the size of array
A. You can use '
std::bitset' in C++ to implement all operations involving
'uintk'.
Now Walk Alone is given an array
A and an integer
k. He found that for any integer
x (0≤x<2k), there exists a positive integer
T such that
randT(x,A)=x, where
Let
f(x)=min{T>0∣randT(x,A)=x}. Walk Alone wants to know the expected value of
f(x) modulo
998244353998 if
x is chosen from
{0,1,…,2k−1} with equal probability.
It can be shown that the answer can always be expressed as an irreducible fraction
x/y, where
x and
y are integers and
y≢0(mod998244353). Output such an integer
a that
0≤a<9982443530 ,0≤a<998244353 and
a⋅y≡x(mod998244353).