Given a NxN matrix A, find the Determinant of A % P.
Input
Multiple test cases (the size of input file is about 3MB, all numbers in each matrix are generated randomly).
The first line of every test case contains two integers , representing N (0 < N < 201) and P (0 < P < 1,000,000,001). The following N lines each contain N integers, the j-th number in i-th line represents A[i][j] (- 1,000,000,001 < A[i][j] < 1,000,000,001).
Output
For each test case, print a single line contains the answer.
Example
Input:
1 10
-528261590
2 2
595698392 -398355861
603279964 -232703411
3 4
-840419217 -895520213 -303215897
537496093 181887787 -957451145
-305184545 584351123 -257712188
Output:
0
0
2
行列式求解摸板题
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int MAXN = 210;
LL mod;
LL a[MAXN][MAXN];
LL det(int n)
{
LL res = 1;
for(int i = 1;i <= n;++i){
for(int j = i + 1;j <= n;++j){
while(a[j][i]){
LL t = a[i][i] / a[j][i];
for(int k = i;k <= n;++k){
a[i][k] = (a[i][k] - t * a[j][k] % mod + mod) % mod;
swap(a[i][k],a[j][k]);
}
res = (-res + mod) % mod;
}
}
res = res * a[i][i] % mod;
}
return res;
}
int main()
{
int n;
while(~scanf("%d %lld",&n,&mod))
{
for(int i = 1;i <= n;++i){
for(int j = 1;j <= n;++j){
scanf("%lld",&a[i][j]);
}
}
LL ans = det(n);
printf("%lld\n",ans);
}
return 0;
}