问题 H: Expectation of Rank

内存限制:256 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述

Let p be a prime number and ��Fp be the finite field with order p. Suppose A is a square matrix of order n and each of its entry is a random variable that uniformly distributed on ��Fp. Please calculate the expectation of the rank of A, i.e., �[rank(�)]E[rank(A)].

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 p when p is a prime number.

When we say ��Fp is a finite field with order p, it means that ��Fp contains exactly p distinct elements, with p being a prime number. The elements of ��Fp are the integers 0,1,2,...,�−10,1,2,...,p1, and the operations of the field are performed modulo p. For instance, if �=5p=5, then �5F5 is the set 0,1,2,3,40,1,2,3,4, and in this field, 2+3=02+3=0 and 4×4=14×4=1.

输入格式

The first line of the input contains an integer T (1≤�≤501T50), denoting the number of test cases.

Each of the following T lines contains two integers �,�n,p (1≤�≤50001n50002≤�≤1092p109), denoting the order of the square matrix A and the prime number p.

It's guaranteed that the sum of n in all test cases will not exceed 50005000.

输出格式

For each test case, output the expectation of the rank of A. You should output the answers modulo 109+7109+7. That is, if the answer is ��QP, you should output �⋅�−1mod109+7PQ1mod109+7, where �−1Q1 denotes the multiplicative inverse of Q modulo 109+7109+7. It can be proved that the answer can always be expressed in this form.

输入样例 复制

2
2 2
2 3

输出样例 复制

812500007
802469143

数据范围与提示

The rank of the matrix[12
21]in �3F3 is 11.

分类标签