Water and Jug Problem
You are given two jugs with capacities x liters and y liters. You have an infinite water supply. Return whether the total amount of water in both jugs may reach target using the following operations:
- Fill either jug completely with water.
- Completely empty either jug.
- Pour water from one jug into another until the receiving jug is full, or the transferring jug is empty.
Example 1
Input
x = 3, y = 5, target = 4Output
trueFollowing the allowed fill, empty, and pour operations, it is possible to leave exactly 4 liters total in the jugs.
Example 2
Input
x = 2, y = 6, target = 5Output
falseThere is no sequence of allowed operations that can make the total amount of water in the two jugs equal to 5 liters.
Constraints
- 1 <= x, y, target <= 10^3