Quaternion inverse
Time limit1sMemory limit256 MB
Given a prime M and up to 100000 quaternions with components modulo M, output the modular inverse of each or zeros if none exists.
- Level
Medium5 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
A quaternion extends the complex numbers. It is written with three imaginary units , , that satisfy , so it has four real components. This problem deals only with the quaternions in the set below, called restricted quaternions.
Because of the relations among , , , the product of two ordinary quaternions is the following.
The product of two restricted quaternions is defined as the product of the same two quaternions taken as ordinary quaternions, with every integer component replaced by its remainder modulo .
Given and a restricted quaternion , find the restricted quaternion with .
Input
The first line has two natural numbers and (), separated by a space. is prime, so its only divisors are 1 and itself, and .
Each of the next lines has four integers , , , () separated by spaces, and they describe .
Output
For each , print on one line the four integers , , , of the restricted quaternion with , separated by spaces. At most one such exists, so the answer is unique. If there is no such , print 0 four times, separated by spaces.