#P9832. Data Generation
Data Generation
Data Generation
Problem Description
Yoshinow2001 is making data for his problem. He wants to generate a random permutation of , so he used the following algorithm:
Here, we can assume that the function is able to generate integer randomly in the set with equal probability.
Now Yoshinow2001 is concerned that this algorithm is not random enough ------ after all, if you want to randomize a permutation, the expected number of elements for should be . So he wants to ask what the mathematical expectation of the final is.
Input
The first line of input is a positive integer representing the number of data cases. For each cases consists of a single line of two integers , separated by a space. Where ,, ensure that is not a multiple of .
Output
For each cases, output a line with a positive integer representing the answer .
Sample Input
3
1 0
1 1
2 1
Sample Output
0
0
1
Source
2023“钉耙编程”中国大学生算法设计超级联赛(4)