This page is still under construction.

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

Complex Numbers

Time limit0.5sMemory limit512 MB

Summary
Given two complex numbers written as (b + c*sqrt(d))/a with a shared squarefree d, print their sum, difference, product, and quotient in the same reduced canonical form.
Level

Medium7 of 10

Topics
Math, Number theory, Implementation, Simulation
Solved
No attempts yet

Problem

b0+c0d0a0+b1+c1d1a1i\displaystyle{{b_0 + c_0 \sqrt{d_0} \over a_0} + {b_1 + c_1 \sqrt{d_1} \over a_1} i}

  • i=−1i = \sqrt{-1}

  • For j=0, 1j=0, \, 1:

    • aj, bj, cj, dja_j, \, b_j, \, c_j, \, d_j are integers
    • aj>0a_j > 0; 0≤dj≠10 \le d_j \ne 1
    • gcd⁡(aj, bj, cj)=1\gcd (a_j, \, b_j, \, c_j) = 1
    • 'cj=0c_j = 0' if and only if 'dj=0d_j = 0'
    • When dj>0d_j > 0, djd_j has no square divisor greater than 11
  • d0=d1d_0=d_1

Given complex numbers AA and BB written in the form above, write a program that prints the values of A+BA+B, A−BA-B, A×BA \times B, and A÷BA \div B.

Input

The first line gives the values a0, b0, c0, d0, a1, b1, c1, d1a_0, \, b_0, \, c_0, \, d_0, \, a_1, \, b_1, \, c_1, \, d_1 of AA, one per position.

The second line gives the values a0, b0, c0, d0, a1, b1, c1, d1a_0, \, b_0, \, c_0, \, d_0, \, a_1, \, b_1, \, c_1, \, d_1 of BB in the same way.

Output

Print four lines. Line one through line four hold the values a0, b0, c0, d0, a1, b1, c1, d1a_0, \, b_0, \, c_0, \, d_0, \, a_1, \, b_1, \, c_1, \, d_1 for A+BA+B, A−BA-B, A×BA \times B, and A÷BA \div B, each expressed in the form described in the problem statement.

Constraints

  • B≠0B \ne 0
  • AA and BB have the same value of d0d_0
  • The input satisfies the conditions of the form described in the problem statement
  • Every number in the input has absolute value at most 1010

Examples1

  1. Example 1

    Input
    2 5 -3 2 3 6 2 2
    6 -4 1 2 2 2 -9 2
    
    Expected output
    6 11 -8 2 6 18 -23 2
    6 19 -10 2 6 6 31 2
    12 22 117 2 36 536 -463 2
    258212 -62625 -56274 2 258212 -78659 60431 2