This page is still under construction.

Parts of this page are still being built. What you see may change.

Matrix Inverse

Interview

Time limit2sMemory limit1024 MB

Summary
For each 2x2 integer matrix, print its inverse over two lines with a case number, guaranteed to have integer entries.
Level

Easy2 of 10

Topics
Math, Matrix, Implementation
Solved
No attempts yet

Problem

For a square n×nn \times n matrix AA, its inverse B=A−1B = A^{-1} is defined as the matrix satisfying the equality

AB=IAB = I

where BB and II are n×nn \times n matrices, and II is the identity matrix with ones along the diagonal and zeros everywhere else.

I=[10…001…0⋮⋮⋱⋮00…1]I = \begin{bmatrix} 1 & 0 & \dots & 0 \\ 0 & 1 & \dots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \dots & 1 \end{bmatrix}

For this problem, you must write a program that finds the inverse of a 2×22 \times 2 matrix.

Input

Each test case is given in two lines. Each line contains two 32-bit signed integers, and the integers aa, bb, cc, dd given in that order are the entries of the matrix to invert.

A=[abcd]A = \begin{bmatrix} a & b \\ c & d \end{bmatrix}

A blank line follows each test case.

Output

For each case, print the case number, then print the inverse of the given matrix over two lines. Every test case is guaranteed to have an inverse (that is, no matrix is singular), and the entries of that inverse are integers. Follow the format of the sample output.

Examples1

  1. Example 1

    Input
    1 0
    0 1
    
    30 29
    1 1
    
    -7 -16
    4 9
    
    
    Expected output
    Case 1:
    1 0
    0 1
    Case 2:
    1 -29
    -1 30
    Case 3:
    9 16
    -4 -7