No.2441 Matrix Power
Problem Statement
You are given as input a square matrix $M$ of order $2$ with integer coefficients.
Find $M^3$.
Here is an explanation for those who are not familiar with matrix multiplication. (Click to expand)
Roughly speaking, a square matrix of order $2$ with integer coefficients is a concept represented as data consisting of integers arranged in $2$ rows and $2$ columns. For example,
$\displaystyle \left( \begin{array}{cc} \displaystyle 1 &\displaystyle 2 \\ \displaystyle 3 &\displaystyle 4 \end{array} \right) $
is an example of a square matrix of order $2$ with integer coefficients. Given $2$ square matrices $A$ and $B$ of order $2$ with integer coefficients, if we write them as
$\displaystyle A = \left( \begin{array}{cc} \displaystyle \textcolor{red}{a} &\displaystyle \textcolor{red}{b} \\ \displaystyle \textcolor{blue}{c} &\displaystyle \textcolor{blue}{d} \end{array} \right), B = \left( \begin{array}{cc} \displaystyle \textcolor{magenta}{e} &\displaystyle \textcolor{purple}{f} \\ \displaystyle \textcolor{magenta}{g} &\displaystyle \textcolor{purple}{h} \end{array} \right) $
(where $\textcolor{red}{a},\textcolor{red}{b},\textcolor{blue}{c},\textcolor{blue}{d},\textcolor{magenta}{e},\textcolor{purple}{f},\textcolor{magenta}{g},\textcolor{purple}{h}$ are integers), then the product $AB$ of $A$ and $B$ is defined by the following formula.
$\displaystyle AB = \left( \begin{array}{cc} \displaystyle \textcolor{red}{a} \textcolor{magenta}{e} + \textcolor{red}{b} \textcolor{magenta}{g} &\displaystyle \textcolor{red}{a} \textcolor{purple}{f} + \textcolor{red}{b} \textcolor{purple}{h} \\ \displaystyle \textcolor{blue}{c} \textcolor{magenta}{e} + \textcolor{blue}{d} \textcolor{magenta}{g} &\displaystyle \textcolor{blue}{c} \textcolor{purple}{f} + \textcolor{blue}{d} \textcolor{purple}{h} \end{array} \right) $
Just as positive integer powers of real numbers are defined using multiplication of real numbers, positive integer powers of matrices are defined using matrix multiplication. Specifically, $M^2$ is defined as the product $MM$ of $M$ and $M$ itself, and $M^3$ is defined as the product $M^2 M$ of $M^2$ and $M$. Find $M^3$ according to this definition.
Input
$\displaystyle M = \left( \begin{array}{cc} \displaystyle M_{1,1} &\displaystyle M_{1,2} \\ \displaystyle M_{2,1} &\displaystyle M_{2,2} \end{array} \right) $
Using the notation above, the input is given from standard input in the following format:
$M_{1,1}$ $M_{1,2}$
$M_{2,1}$ $M_{2,2}$
- Line $1$ contains $M_{1,1}, M_{1,2}$, separated by a half-width space.
- Line $2$ contains $M_{2,1}, M_{2,2}$, separated by a half-width space.
Constraints
The input satisfies the following constraints:
- Each entry of $M$ is an integer between $-100$ and $100$, inclusive.
Output
$\displaystyle M^3 = \left( \begin{array}{cc} \displaystyle N_{1,1} &\displaystyle N_{1,2} \\ \displaystyle N_{2,1} &\displaystyle N_{2,2} \end{array} \right) $
Using the notation above, output in the following format:
$N_{1,1}$ $N_{1,2}$
$N_{2,1}$ $N_{2,2}$
- On line $1$, output $N_{1,1}, N_{1,2}$, separated by a half-width space.
- On line $2$, output $N_{2,1}, N_{2,2}$, separated by a half-width space.
Print a newline at the end.
Sample
Sample 1
Input
0 0 0 0
Output
0 0 0 0
$ \left( \begin{array}{cc} \displaystyle 0 &\displaystyle 0 \\ \displaystyle 0 &\displaystyle 0 \end{array} \right)^3 = \left( \begin{array}{cc} \displaystyle 0 &\displaystyle 0 \\ \displaystyle 0 &\displaystyle 0 \end{array} \right) $
holds.
Sample 2
Input
1 0 0 1
Output
1 0 0 1
$ \left( \begin{array}{cc} \displaystyle 1 &\displaystyle 0 \\ \displaystyle 0 &\displaystyle 1 \end{array} \right)^3 = \left( \begin{array}{cc} \displaystyle 1 &\displaystyle 0 \\ \displaystyle 0 &\displaystyle 1 \end{array} \right) $
holds.
Sample 3
Input
1 0 0 -1
Output
1 0 0 -1
$ \left( \begin{array}{cc} \displaystyle 1 &\displaystyle 0 \\ \displaystyle 0 &\displaystyle -1 \end{array} \right)^3 = \left( \begin{array}{cc} \displaystyle 1 &\displaystyle 0 \\ \displaystyle 0 &\displaystyle -1 \end{array} \right) $
holds.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。