Skip to content
QuantReadySign In
#453easyMatrix Operations

2x2 Matrix Multiplication

Time Limit: 2sMemory: 256MB

Problem

Given two 2×22 \times 2 matrices AA and BB, compute their product C=ABC = AB.

Cij=k=12AikBkjC_{ij} = \sum_{k=1}^{2} A_{ik} B_{kj}

For 2x2 matrices, this expands to four entries, each being a dot product of a row of AA with a column of BB.

Input Format

Eight space-separated values: a11 a12 a21 a22 b11 b12 b21 b22

(Matrix AA in row-major order, then matrix BB in row-major order.)

Output Format

Four space-separated values: c11 c12 c21 c22, each to 4 decimal places.

Examples

Example 1
Input(Eight space-separated values: a11 a12 a21 a22 b11 b12 b21 b22)
1 2 3 4 5 6 7 8
Output
19.0000 22.0000 43.0000 50.0000

A=[[1,2],[3,4]] * B=[[5,6],[7,8]] = [[19,22],[43,50]].

Example 2
Input(Eight space-separated values: a11 a12 a21 a22 b11 b12 b21 b22)
1 0 0 1 3 4 5 6
Output
3.0000 4.0000 5.0000 6.0000

Identity times B equals B.

Constraints

  • -1000 ≤ matrix entries ≤ 1000
  • Output to 4 decimal places
Loading interactive editor…