#P11173. Nilpotent Matrix Power Sum

    ID: 13238 Type: Default 1000ms 256MiB

Nilpotent Matrix Power Sum

Nilpotent Matrix Power Sum

Given an \(n \times n\) matrix \(A\), define \(f(A)\) as the smallest positive integer \(b\) satisfying
\[ A^b = O, \]
where \(O\) is the zero matrix (i.e. every element is 0). If no such \(b\) exists, we define \(f(A)=0\).

You are also given an integer \(a\). Consider all \(n \times n\) matrices whose entries are integers in the range \([0,a)\). There are exactly \(a^{n^2}\) such matrices. Your task is to compute the sum

\[ S = \sum_{A} f(A) \]

over all possible matrices \(A\), and output \(S \bmod 202407031\).

Note: For each matrix \(A\), if there exists a positive integer \(b \le n\) such that \(A^b = O\), then \(f(A)\) is defined as the least such \(b\); otherwise, \(f(A)=0\>.

inputFormat

The input consists of a single line containing two integers \(n\) and \(a\), where \(n\) is the dimension of the matrix and \(a\) defines the range \([0, a)\) of each matrix element.

For example:

2 2

outputFormat

Output a single integer: the sum of \(f(A)\) over all possible \(n \times n\) matrices with entries in \([0,a)\), modulo 202407031.

For example, if the input is:

1 2

then the output should be:

1

sample

1 2
1