#GL0000353. Đong nước bằng hai bình (Jugs Hard)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đong nước bằng hai bình (Jugs Hard)
Jugs Hard
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
You have two unmarked water jugs of capacities and and an unlimited water supply. Both jugs are initially empty. One operation may:
- Fill either jug completely from the supply.
- Empty either jug completely.
- Pour from one jug to the other until the source is empty or the destination is full.
Determine whether it is possible to obtain exactly units in at least one jug at any time. In particular, is possible at the start.
PHOJ adaptation: Each file contains a single triple instead of multiple original test cases; output remains Yes or No.
Input
A single line with integers .
Output
Yes if possible and No otherwise. Output is case-sensitive.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
8 1 5
Output
Yes
Explanation
The 1-unit jug can repeatedly remove one unit from the 8-unit jug until 5 remain.
Example 2
Input
4 4 3
Output
No
Explanation
The capacities have gcd 4; only multiples of 4 can be measured.
Example 3
Input
5 3 4
Output
Yes
Explanation
Fill the 5-jug, pour into the 3-jug leaving 2; empty the 3-jug, move 2 into it, refill the 5-jug and pour 1 to leave 4.