Lord of the Characteristic Polynomials (2)
Time limit5sMemory limit1024 MB
Given an n by n matrix whose entries are a + b*sqrt(D), find each coefficient of its characteristic polynomial as p + q*sqrt(D), reduced modulo M.
- Level
Hard8 of 10
- Topics
- Matrix, Math, Number theory
- Solved
- No attempts yet
Problem
For an matrix , the determinant is defined as follows, where is the entry in row and column . is the set of permutations of , so holds for every .
The characteristic polynomial of is a polynomial of degree in , defined as .
In this problem the entries are special. You are given an integer that is not divisible by any perfect square greater than 1. Every entry of has the form with integers and , so each entry is an element of the set
The coefficients of are also elements of , and this can be proven. Each has unique integers and . Given an integer , write a program that outputs the remainder of each and divided by .
Input
The first line contains the size of the matrix, the integer used for division, and the integer .
Each of the next lines contains integers. If the -th number on line is and the -th number is , then .
Output
Print lines. On line , print the remainders of and divided by , separated by a space.
The remainder of an integer divided by is the smallest non-negative integer such that is a multiple of .
Constraints
- , and is not divisible by any perfect square greater than 1.
- For all , if , then .
Hints
- For each , there are unique integers such that .