365. Water and Jug Problem
Description
You are given two jugs with capacities x and y litres.
There is an infinite amount of water supply available.
You need to determine whether it is possible to measure exactly z litres using these two jugs.
If z liters of water is measurable, you must have z liters of water contained within **one or both** buckets by the end.
Example
Input: x = 3, y = 5, z = 4
Output: True
Solution
问题转化为: 给定 n 个容器 a1, a2,…,an。 最后需要 m 单位的水。
即求一次不定方程a1*x1 + a2*x2 + ... + an*xn = m
的整数解。
原问题中, 只有两个容器 x, y。方程变成: X*x1 + Y*y1 = Z
是否有整数解。
Hint