class Solution {

```
int gcd(int x,int y)
{
return (!x ? y : gcd(y%x,x));
}
```

public:

bool canMeasureWater(int x, int y, int z) {

```
/* Trivial cases */
if (!z) //empty measurement
return true;
if(z > x+y || (!x && !y)) // More than capacity or measuring capacities zero
return false;
if(x == z || y == z) // Same as desired
return true;
return (z % gcd(x,y) == 0);
}
```

};