注意到 z=ax+by,(a,b)取任意整数
所以 z%gcd(x,y)=0
365. 水壶问题
class Solution {
public:
int gcd(int x,int y){
if (y==0) return x;
else return gcd(y,x%y);
}
bool canMeasureWater(int x, int y, int z) {
int tip=gcd(x,y);
if (tip>0){
if (z%tip==0 && x+y>=z) return true;
}
else{
if (z==0) return true;
else return false;
}
return false;
}
};