nullspace_basis

(256000 kilobytes, 1000 milliseconds)

Submissions: 0 · Accepted: 0

Submit code

Statement

Basis of a null space

All arithmetic is performed in

\[ \mathbb{F}_p, \qquad p = 1\,000\,000\,007. \]

For an \(n \times m\) matrix \(A\), its **null space** is

\[ \ker(A)=\{x\in\mathbb{F}_p^m : Ax=0\}. \]

Output any basis of \(\ker(A)\). The basis and its ordering are not unique.

Input

The first line contains \(n\) and \(m\). The next \(n\) lines contain the
matrix \(A\), with \(m\) entries per line.

Output

Print an integer \(k\), the dimension of the null space. Then print \(k\)
vectors, one per line, each with \(m\) entries. Every vector must satisfy
\(Ax=0\), and the vectors must be linearly independent and span all such
vectors.

The expected dimension is \(k=m-\operatorname{rank}(A)\). Entries are compared
modulo \(p\), so any integer representative is accepted.

Constraints