Time

12:55:13
23 May 2012
Version for print

The Billiards

prb58

   Billiards is a rectangle with the sizes of MxN, where M and N is natural numbers. From an overhead left pocket a bullet takes off under the corner of 450 to the nearby sides. The pockets are placed only in the corners of billiards. You have to define the quantity of collisions of bullet with the sides of billiards, after which it again will get in one of the pockets, and the number of pocket in which will get in bullet. You have to consider that friction absents, a collision is absolutely resilient, and bullet is a material point.


Specifications

   Input

   In the front row, two numbers M and N, 1M, N2000000000. Numbering Luz clockwise from top left pocket, from which viletel ball, according to the picture. M - horizontal side of the billiard, N - the vertical side of the billiard.

   Output

   Two numbers through gap: the number of reflections of the ball and the number of pockets in which the ball drops.


Problem information

Time Limit: 1 seconds
Memory Limit: 64 MB
Balls for the passed test: 10
Complexity: 41% 85/143
Classes: Simple mathematics

Example

Example input

2 1

Example output

1 2


← The Butterfly – Medical Attendan Problems The Cells are Painted out →