|
|||
A Flea on a Chessboard
An infinite chessboard is obtained by extending a finite chessboard to the right and up infinitely. Each square of the chessboard is either black or white with the side of S millimiters (0 < S < 1000). The leftmost bottom square of the chessboard is black. A flea is positioned on the chessboard at the point (x, y) (given in millimeters) and makes jumps by jumping dx millimeters to the right and dy millimiters up (0 < dx, dy), that is, a flea at position (x, y) after one jump lands at position (x + dx, y + dy). Given the starting position of the flea on the board, your task is to find out after how many jumps the flea will reach a white square. If the flea lands on a boundary between two squares, then it does not count as landing on the white square. Note that it is possible that the flea never reaches a white square. Input SpecificationEach test case consists of one line of input containing five nonnegative numbers separated by whitespace and giving S, x, y, dx, and dy. An input line containing five zeroes follows the last test case. Output SpecificationFor each test case, print one line of output in the format shown in the sample. Sample Input
Output for Sample Input
|
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |