class Solution {
public:
bool canMeasureWater(int x, int y, int z) {
if(z > x && z > y) return false;
return z%gcd(x, y) == 0;
}
private:
int gcd(int a, int b){
return b == 0?a:gcd(b, a%b);
}
};
C++ solution using Euclidean Algorithm

@Ren.W Well, in the practice, z >x and z>y should be correct. For example, z = 3 and a = 1 and b = 2. But in this question, due to some unknown reasons, that case is false always.