#P6130. Red Envelope Distribution
Red Envelope Distribution
Red Envelope Distribution
Party organizer Jun Raku has exactly \(1\) unit of money in his red envelope. He decides to distribute it randomly among \(n\) people using the following algorithm:
a[0] = 0, a[n] = 1 for i = 1 to n-1 do{ a[i] = rand() // returns a uniformly random real number in [0,1] } sort(a) // sort the array in increasing order for i = 1 to n do{ money[i] = a[i] - a[i-1] }
After the above process the amounts money[i] sum to \(1\). Then Jun Raku sorts these \(n\) allocated amounts so that \[ money_{(1)} \le money_{(2)} \le \cdots \le money_{(n)}. \]
Your task is: for a given query with parameters \(n\) and \(k\), determine the expected value of the \(k\)th smallest amount \(money_{(k)}\) modulo \(998244353\). There will be \(T\) queries and, to reduce the output size, you are required to output the XOR (bitwise exclusive‐or) of all \(T\) answers (each computed modulo \(998244353\)).
Note: To keep matters simple, assume that \(n\) can only be \(2\) or \(3\).
inputFormat
The first line contains an integer \(T\), the number of test cases. Each of the next \(T\) lines contains two integers \(n\) and \(k\) where \(n \in \{2,3\}\) and \(1 \le k \le n\).
outputFormat
Output a single integer: the XOR (bitwise exclusive‐or) of all \(T\) answers (each answer is computed modulo \(998244353\)).
sample
2
2 1
2 2
XOR of (1/4 mod 998244353) and (3/4 mod 998244353)