Powers of a matrix

Given a 2 × 2 matrix M of natural numbers, a natural number n and a
natural number m, compute M^(n). To avoid overflows, compute every
element of M^(n) mod  m.

Input

Input consists of several cases, each with M₁₁, M₁₂, M₂₁ and M₂₂ in this
order, followed by n and m. Assume that the elements of M are not larger
than 500, 0 ≤ n ≤ 10⁹, and 2 ≤ m ≤ 1000.

Output

For every case, print the elements of M^(n) mod  m in two lines
following the format of the sample. Print a line with 10 dashes after
every matrix.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:10:48.171Z

© Jutge.org, 2006–2026.
https://jutge.org
