class Solution {
public boolean canMeasureWater(int x, int y, int z) {
if (x == z || y == z || x + y == z) return true;
if (x + y < z) return false;
return z % GCD(x, y) == 0;
}
public int GCD(int a, int b) {
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
}
reference: https://leetcode.com/problems/water-and-jug-problem/discuss/83715/Math-solution-Java-solution