#include<stdio.h>
int rev[100000];
int M, T;
int vis[4];
int ord[4];
int mult(int x, int e)
{
if(e == 1) return x;
long long tmp = mult(x, e>>1);
tmp = (tmp * tmp) % M;
if (e & 1) tmp = (tmp * x) % M;
return (int)tmp;
}
int main()
{
scanf("%d %d", &M, &T);
rev[1] = 1;
for(int i = 2; i < M; i++)
rev[i] = mult(i, M-2);
int a, b, c, d;
while(T--){
scanf("%d %d %d %d", &a, &b, &c, &d);
long long f[4][4] = {
{a,M-b,M-c,M-d},
{b,a,M-d,c},
{c,d,a,M-b},
{d,M-c,b,a}
};
//for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) if(
long long v[4] = {1,0,0,0};
for(int t = 0; t < 4; t++) vis[t] = 0;
for(int col = 0; col < 4; col++)
{
int row;
for(row = 0; row < 4; row++) if(vis[row] == 0 && f[row][col] != 0) break;
if(row == 4) goto FAIL;
vis[row] = 1;
ord[col] = row;
int i, j;
for(i = row; i == row; i++)
{
long long am = f[i][col];
for(j = 0; j < 4; j++)
f[i][j] = f[i][j] * rev[am] % M;
v[i] = v[i] * rev[am] % M;
}
for(i = 0; i < 4; i++)
{
if(f[i][col] == 0) continue;
if(i == row) continue;
long long am = f[i][col];
for(j = 0; j < 4; j++)
f[i][j] = (f[i][j] - f[row][j] * am + M * M) % M;
v[i] = (v[i] - v[row] * am + M * M) % M;
}
}
int ass[4];
for(int col = 0; col < 4; col++)
{
int row = ord[col];
int val = v[row] * rev[f[row][col]] % M;
printf("%d ", val);
ass[col] = val;
}
printf("\n");
continue;
FAIL:
printf("0 0 0 0\n");
continue;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |