#GL0000272. Ngai vàng (Throne)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Ngai vàng (Throne)
Throne
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are chairs arranged in a circle, including one special chair called the throne. Takahashi initially sits chairs clockwise from the throne.
During each move, he travels exactly chair positions clockwise and sits on the resulting chair. Passing the throne during a move does not count; he must finish the move on the throne.
Find the minimum number of moves needed to reach the throne, or output -1 if it is impossible.
Input
One line contains three integers .
Output
Print the minimum number of moves, or -1 if the throne cannot be reached.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Example 1
Input
10 4 3
Output
2
Explanation
Starting at position , two jumps of size reach positions and .
Example 2
Input
1000 11 2
Output
-1
Explanation
The starting position is odd and each jump is even, so the throne at position cannot be reached.
Example 3
Input
998244353 897581057 595591169
Output
249561088
Explanation
The reported number is the smallest nonnegative solution of the congruence.
Example 4
Input
10000 6 14
Output
3571
Explanation
The sum is divisible by , and this is the smallest valid move count.