This page is still under construction.

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

Square Bounce

Time limit7sMemory limit1024 MB

Summary
A ray starts at (-1,0) inside a unit square, bounces n times off the sides at equal angles, and you report the rational coordinates of the n-th hit point in lowest terms.
Level

Medium6 of 10

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

Problem

Given a square in the plane with corners at (−1,−1)(-1,-1), (−1,1)(-1,1), (1,1)(1,1) and (1,−1)(1,-1), we fire a ray from point (−1,0)(-1,0) into the interior of the square on a path with a given slope. The ray bounces off of the sides of the square with an angle of reflection which is the same as the angle of incidence to the side at the point of intersection.

After a number of bounces, the ray intersects one of the square's sides again at some point which has rational coordinates. Find those rational coordinates in reduced form.

Input

The single line of input contains three integers aa, bb and nn (1≤a,b,n≤1061 \le a,b,n \le 10^6, gcd⁡(a,b)=1\gcd(a,b)=1), where the slope of the ray's initial path is a/ba/b, and there are nn bounces. Note that aa and bb are relatively prime. The slope will be chosen so that the ray never bounces at a corner of the square.

Output

Output a single line with four space-separated integers pp, qq, ss and tt, where (p/q,s/t)(p/q, s/t) is the final point where the ray hits a side of the square, p/qp/q and s/ts/t are in reduced form, and the denominators (qq and tt) are positive. If one of the coordinates has value 00, output it as 0 1.

Hint

The following is a picture of the first sample:

Examples3

  1. Example 1

    Input
    1 1 3
    
    Expected output
    -1 1 0 1
    
  2. Example 2

    Input
    1 7 4
    
    Expected output
    -1 1 6 7
    
  3. Example 3

    Input
    355 113 123456
    
    Expected output
    1 1 -58 113