题目:
题解:
bool canMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity) {
int j1 = jug1Capacity < jug2Capacity ? jug1Capacity : jug2Capacity, j2 = jug1Capacity > jug2Capacity ? jug1Capacity : jug2Capacity;
if (targetCapacity > j1 + j2) return false;
if (targetCapacity % j1 == 0) return true;
for (long j = j2, jmax = (long)j1 * j2; j < jmax; j += j2)
if ((targetCapacity - j) % j1 == 0 || (targetCapacity + j) % j1 == 0) return true;
return false;
}