Two Jugs
Time limit2sMemory limit256 MB
Given two jug capacities and a target volume, decide whether fill, empty, and pour operations can leave exactly that volume in one jug.
- Level
Medium4 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
You have two empty jugs and a tap that fills a jug. The tap can only fill a jug all the way, because the jugs carry no volume markings and you cannot stop at a chosen level.
You may empty either jug at any time.
You may also pour water from one jug into the other. If the poured water is more than the receiving jug can still take, the receiving jug ends up full and the rest stays in the jug it came from.
Given the volumes of the two jugs, decide whether one of them can end up holding exactly the wanted volume of water.
Input
The first line contains the number of test cases (). Each of the next lines contains three integers , , and separated by spaces. Here and are the volumes of the two jugs (), and is the volume of water you want ().
Output
For each test case, print one line. Print Yes if one of the two jugs can hold exactly units of water, and No otherwise.