luogu#P7776. 【模板】特征多项式

【模板】特征多项式

Background

This is a template problem.

Problem Description

Given nn and an n×nn\times n matrix AA, find its characteristic polynomial modulo 998244353998244353.

Input Format

The first line contains a positive integer nn.
Next nn lines each contain nn non-negative integers, representing the matrix AA.

Output Format

Output one line with n+1n+1 positive integers, representing the coefficients of its characteristic polynomial pA(x)p_A(x) from low degree to high degree.

3
1 2 3
4 5 6
7 8 9
0 998244335 998244338 1 

Hint

For an n×nn\times n matrix AA, let its characteristic polynomial be pA(x)p_A(x), which satisfies

pA(x)=det(xInA)p_A(x)=\det(xI_n-A)

where InI_n is the n×nn\times n identity matrix.

For 10%10\% of the testdata, 1n51\le n\le 5.
For 40%40\% of the testdata, 1n501\le n\le 50.
For another 10%10\% of the testdata, 1in,1ji1,Ai,j=0\forall1\le i\le n,1\le j\le i-1,A_{i,j}=0, i.e. AA is an upper triangular matrix.
For another 20%20\% of the testdata, 1in,1ji2,Ai,j=0\forall1\le i\le n,1\le j\le i-2,A_{i,j}=0, i.e. AA is an upper Hessenberg matrix.
For 100%100\% of the testdata, 1n5001\le n\le 500, Ai,j[0,998244352]A_{i,j}\in[0,998244352].

Translated by ChatGPT 5