luogu#P4783. 【模板】矩阵求逆

【模板】矩阵求逆

Problem Description

Find the inverse matrix of an N×NN\times N matrix. Output the answer modulo 109+7{10}^9+7.

Input Format

The first line contains an integer NN, which represents the size of the matrix.

The next NN lines each contain NN integers. The number in row ii and column jj represents the element aija_{i j} of the matrix.

Output Format

If the matrix is invertible, output NN lines, each containing NN integers. The number in row ii and column jj represents the element bijb_{i j} of the inverse matrix, taken modulo 109+7{10}^9+7.

Otherwise, output only one line: No Solution.

3
1 2 8
2 5 6
5 1 2
718750005 718750005 968750007
171875001 671875005 296875002
117187501 867187506 429687503
3
3 2 4
7 2 9
2 4 3
No Solution

Hint

For 30%30\% of the testdata, N100N\le 100.

For 100%100\% of the testdata, N400N\le 400, and all 0aij<109+70 \le a_{i j} < {10}^9 + 7.

Translated by ChatGPT 5