#P6130. 随机红包
随机红包
Description
There is yuan in the setter’s red packet, and he wants to randomly split this yuan among 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 , 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 -th smallest amount.
Since he wants to use this value to estimate how many red packets to send, he will ask you queries.
To avoid precision loss, output the answer modulo .
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 , the number of test cases.
For each test case, one line contains two integers .
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, , so the answer is .
For the second query, the larger amount is uniformly distributed on , and its expectation is , which becomes after taking modulo.
For the third query, the smaller amount is uniformly distributed on , and its expectation is , which becomes after taking modulo.
The XOR sum is .
[Constraints]
This problem uses bundled testdata.
: , .
: .
: .
: .
: no additional constraints.
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号