#P9884. Expectation of Rank
Expectation of Rank
Expectation of Rank
Problem Description
Let be a prime number and be the finite field with order . Suppose is a square matrix of order and each of its entry is a random variable that uniformly distributed on . Please calculate the expectation of the rank of , i.e., . In mathematics, a finite field, also known as a Galois field, is a set that contains a finite number of elements. These elements follow the operations of multiplication, addition, subtraction, and division, all of which satisfy the basic rules of arithmetic. The most common examples of finite fields are given by the integers mod when is a prime number. When we say is a finite field with order , it means that contains exactly distinct elements, with being a prime number. The elements of are the integers , and the operations of the field are performed modulo . For instance, if , then is the set , and in this field, and .
Input
The first line of the input contains an integer (), denoting the number of test cases. Each of the following lines contains two integers (, ), denoting the order of the square matrix and the prime number . It's guaranteed that the sum of in all test cases will not exceed .
Output
For each test case, output the expectation of the rank of . You should output the answers modulo . That is, if the answer is , you should output , where denotes the multiplicative inverse of modulo . It can be proved that the answer can always be expressed in this form.
Sample Input
2
2 2
2 3
Sample Output
812500007
802469143
Hint
The rank of the matrix
in is .
Source
2023“钉耙编程”中国大学生算法设计超级联赛(8)