#P6130. 随机红包

随机红包

Description

There is 11 yuan in the setter’s red packet, and he wants to randomly split this 11 yuan among nn people.

To make it random, he designed the following algorithm to distribute it (in pseudocode):

a[0]=0,a[n]=1
for i=1 to n-1 do{
    a[i]=rand()
}
sort(a)
for i=1 to n do{
    money[i]=a[i]-a[i-1]
}

Here, the function rand() returns a real number uniformly at random in [0,1][0,1], and the function sort() sorts an array in increasing order.

Now, the setter wants to know the expected value of the amount received by the person who gets the kk-th smallest amount.

Since he wants to use this value to estimate how many red packets to send, he will ask you TT queries.

To avoid precision loss, output the answer modulo 998244353998244353.

To avoid excessive output, output the XOR sum of all answers.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, the number of test cases.

For each test case, one line contains two integers n,kn, k.

Output Format

Output one integer in a single line, representing the XOR sum of the answers to all queries.

3
1 1
2 2
2 1
574619649

Hint

[Sample Explanation]

For the first query, n=k=1n=k=1, so the answer is 11.

For the second query, the larger amount is uniformly distributed on [12,1][\dfrac{1}{2},1], and its expectation is 34\dfrac{3}{4}, which becomes 249561089249561089 after taking modulo.

For the third query, the smaller amount is uniformly distributed on [0,12][0,\dfrac{1}{2}], and its expectation is 14\dfrac{1}{4}, which becomes 748683265748683265 after taking modulo.

The XOR sum is 574619649574619649.


[Constraints]

This problem uses bundled testdata.

Subtask 1 (4 pts)\text{Subtask 1 (4 pts)}: n10n \le 10, k=1k=1.

Subtask 2 (16 pts)\text{Subtask 2 (16 pts)}: n5×103n \le 5 \times 10^3.

Subtask 3 (20 pts)\text{Subtask 3 (20 pts)}: k=1k=1.

Subtask 4 (28 pts)\text{Subtask 4 (28 pts)}: n105n \le 10^5.

Subtask 5 (32 pts)\text{Subtask 5 (32 pts)}: no additional constraints.

For 100%100\% of the testdata, 1kn1071 \le k \le n \le 10^7, 1T2×1051 \le T \le 2 \times 10^5.

Translated by ChatGPT 5