Higgs Boson

Time limit1sMemory limit128 MB

Summary
Given two particles whose polar radius and angle move linearly in time, find the earliest rational time t >= 0 when their positions coincide, or report that they never do.
Level

Hard8 of 10

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

Problem

It has been 100 years since the first Higgs boson was detected, and particle physics is now a mainstream subject in every high school. Naturally, kids love that they can create tiny black holes with their portable particle accelerators and show them off to their friends. Although even a portable accelerator could in principle create a black hole large enough to swallow the whole planet, the devices are programmed to fire particles only when that catastrophic side effect is impossible.

Your granddaughter is trying to create her own black holes with a portable accelerator kit made of two small particle accelerators, each of which fires one boson-sized particle. Both particles are launched at the same instant, and a black hole appears the moment they collide. She does not know how long she will have to wait for that to happen. Fortunately, each accelerator predicts its particle's trajectory by displaying four integers, called AA, BB, CC, and DD. Substituting them into

r=At+Br = A t + B

θ=Ct+D\theta = C t + D

gives the particle's trajectory in polar coordinates: the radius rr is measured in distance units and the angle θ\theta in degrees. Time tt is measured in time units and is always a rational value that can be written as an irreducible fraction.

In polar coordinates a point has infinitely many representations. In general, the point (r,θ)(r, \theta) can also be written as (r, θ±k×360°)(r,\ \theta \pm k \times 360°) or (−r, θ±(2k+1)×180°)(-r,\ \theta \pm (2k + 1) \times 180°) for any integer kk. Moreover, the origin (r=0r = 0) can be written as (0,θ)(0, \theta) for any θ\theta.

Using the parameters reported by the two accelerators, your granddaughter wants to know whether the particles will ever collide and, if so, when the first collision happens. After the first collision the trajectories can no longer be predicted, so only the first possible collision matters.

She is brilliant and deeply knowledgeable about particle physics, but she cannot program computers, so she is digging through her grandparent's old programming-contest notebook. Luckily for you, there is a note saying you once wrote exactly this program. Now it is time to write it again.

Input

The input consists of several test cases, one per line. Each test case contains eight integers separated by single spaces:

A1 B1 C1 D1 A2 B2 C2 D2(−104≤A1,B1,C1,D1,A2,B2,C2,D2≤104)A_1\ B_1\ C_1\ D_1\ A_2\ B_2\ C_2\ D_2 \quad (-10^4 \le A_1, B_1, C_1, D_1, A_2, B_2, C_2, D_2 \le 10^4)

The first four values (A1,B1,C1,D1A_1, B_1, C_1, D_1) are the parameters shown by the first accelerator, and the last four (A2,B2,C2,D2A_2, B_2, C_2, D_2) are those shown by the second accelerator when both particles are launched.

The input ends with a line of eight zeros (A1=B1=C1=D1=A2=B2=C2=D2=0A_1 = B_1 = C_1 = D_1 = A_2 = B_2 = C_2 = D_2 = 0), which must not be processed as a test case — those are the values the accelerators would show if launching the particles would create a planet-swallowing black hole. Note that 00 is otherwise a valid input value; only the line consisting entirely of zeros terminates the input.

Output

For each test case, output a line with two non-negative integers tat_a and tbt_b separated by a single space. If the particles can never collide, print ta=tb=0t_a = t_b = 0. Otherwise, ta/tbt_a / t_b must be the earliest collision time written as an irreducible fraction; even when the time is an integer, the denominator must still be printed as 11.

Examples1

  1. Example 1

    Input
    1 1 180 0 2 0 180 360
    10 10 360 0 -24 18 180 72
    5 5 180 0 -12 9 10 40
    -9 5 5 180 2 5 5 180
    0 0 0 0 0 0 0 0
    
    Expected output
    1 1
    0 0
    4 17
    0 1