P11173 「CMOI R1」We Want To Run / Nilpotent

Background

![](bilibili:BV1qW4y1Q7Ce) $\small\color{white}54^{\text{th}}\text{Problem by ArCu}.$

Description

For an $n \times n$ matrix $A$, define $f(A)$ as the smallest positive integer $b$ such that $A^b = O$. If no such integer exists, then $f(A)=0$. Here $O$ is the zero matrix, i.e. the matrix whose all entries are $0$. Given $n,a$, there are $a^{n^2}$ different $n \times n$ matrices whose every entry is an integer in $[0,a)$. Compute the sum of $f(A)$ over all these $a^{n^2}$ possible matrices $A$. Output the answer modulo $202407031$.

Input Format

One line with two integers $n,a(1\leq n\leq 600,0

Output Format

One line with one integer, representing the answer you computed.

Explanation/Hint

$\text{Sample 1 Explanation}:$ Note that for any positive integer $b$, $\begin{bmatrix}1&0\\1&1\end{bmatrix}^b\neq O$, so $f\left(\begin{bmatrix}1&0\\1&1\end{bmatrix}\right)=0$. Also, $\begin{bmatrix}0&0\\1&0\end{bmatrix}^2=O$, so $f\left(\begin{bmatrix}0&0\\1&0\end{bmatrix}\right)=2$. There are $2^4=16$ possible matrices in total. The only ones with $f(A)\neq 0$ are $$f\left(\begin{bmatrix}0&0\\0&0\end{bmatrix}\right)=1,f\left(\begin{bmatrix}0&0\\1&0\end{bmatrix}\right)=f\left(\begin{bmatrix}0&1\\0&0\end{bmatrix}\right)=2$$ So the answer is $1+2+2=5$. $\text{Details of Subtasks}:$ All testdata satisfy $1\leq n\leq 600,0