| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 9046 | Big Mod |
|
| 9047 | Determinant of A Matrix |
|
Description
Calculate R = (BP) mod M for large B, P, and M. Integer B and P are in the range 0 to 2147483647 (=231 – 1) inclusive. Integer M is in the range 1 to 46340 inclusive. Note you cannot calculate R directly because M is too large.
Input
There are multiple test cases. Each test case is given in three lines, containing B, P, and M in each line.
Output
For each test case, output the answer R in a single line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given an n×n matrix A,
,
its determinant can be defined recursively as follows.

where M1,j is an (n–1)×(n–1) matrix, defined by removing the first row and the jth column of A,

For example,


.
Input
The first line contains an integer t (1 <= t <= 20), which indicates the number of test cases in the input. Each case starts with an integer n (2 <= n <= 8), specifying the size of the square matrix A. Then following next n lines, each line containing n integers, define the entries of the matrix A. The range of values in the entries is from -5 to 5.
Output
For each case, output one line with the determinant of matrix A.