| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 82 | 28 | 18 | 32.143% |
Two players are playing the following game:
They sit in front of two non-empty heaps of balls. For clarity, let us denote by A the less (or mostly equal) count of balls in the heaps. The other one is denoted by B (i.e., A ≤ B). The starting ratio A : B = α is important throughout the course of the concrete game and remains intact, no matter how the numbers in the heaps change. The players move consecutively, taking at least one ball from at least one of the heaps. The one of them who cannot make a move, or makes a wrong move, loses the game. So the one, who has played the last correct move, wins.
Let us denote by x the number of balls, taken from one of the heaps, and by y the number of balls, taken from the other heap. We assume denoted by x the less (or mostly equal to the other) count of taken balls. So we can state a simple rule for a move to be correct:
Let us consider an example, where A=12, B=18. In this concrete game the wrong ratio of taken balls is x:y = α = 12:18 = 2:3. Every other ratio of taken balls is correct. Here are some wrong (and therefore – losing) moves for the first player:
We can indicate many correct moves for the first player: to take one ball from any heap (0:1 = 0 ≠ α); to take a whole heap (for example – the second one, 0:18 = 0 ≠ α); to take maximum balls (12) from each heap (12:12 = 1 ≠ α); to take 10 balls from A and 5 from B (5:10 = 1:2 ≠ α) etc. Of course, it is wrong if the player wants to take from a heap more balls than those left in it. And do not forget to take at least one ball from any heap. The “move” x = y = 0 (i.e., “I am leaving the situation intact.”) is wrong (hence losing).
Design a program arelgame, which calculates the number of the winning first moves for the first player. A move is said to be “winning” if it leads to success, no matter how good or bad are the moves of the opponent.
One line is read from the standard input, which contains only two space separated positive integers. These are the number of balls in the first, and the number of balls in the second heap, respectively.
The program should send to the standard output one line, containing only one non-negative integer: the number of the winning first moves for the first player.
The number of balls in each heap does not exceed 1018.
3 2
0
There is no winning move for the first player, while each correct move of his side leads to a direct loss – the second player can take everything left.
6 18
2
α = 6:18 = 1:3
The winning moves for the first player are as follows: