Hard Linear Algebra Problem
Time limit1sMemory limit1024 MB
Given two invertible matrices A and B over a prime field, count the columns i where swapping column i between them keeps both invertible, for each cyclic shift of A.
- Level
Hard8 of 10
- Topics
- Matrix, Linked list, Math
- Solved
- No attempts yet
Problem
The affinity of two invertible matrices and over is the number of indices () that satisfy the following condition.
- If the -th column of and the -th column of are swapped, both and are still invertible.
In other words, the affinity is an integer from to .
Define the matrix as the matrix obtained from by moving its leftmost column to the rightmost position. .
For each integer with , find the affinity of and .
Input
The first line contains a positive integer .
From the second line, the next lines give the matrix . Each line contains integers separated by spaces, and the -th integer on the -th line is .
From line , the next lines give the matrix . Each line contains integers separated by spaces, and the -th integer on the -th line is .
Output
Print integers on the first line, separated by spaces. The -th integer is the affinity of and .
Constraints
- Each entry of the matrices is an integer from to .
- and are invertible.