#C3592. Measuring Water with Two Jugs

    ID: 47036 Type: Default 1000ms 256MiB

Measuring Water with Two Jugs

Measuring Water with Two Jugs

You are given two jugs with capacities \(a\) and \(b\) liters and a target amount \(c\) liters. Your task is to determine whether it is possible to measure exactly \(c\) liters using the two jugs. You can perform operations such as filling a jug completely, emptying a jug, or pouring water from one jug to the other until one jug is either empty or full.

The problem can be solved using the mathematical fact that if \(c\) liters is measurable, then \(c\) must be a multiple of \(\gcd(a, b)\), and \(c\) should not exceed \(a + b\). In other words, if \(c \leq a+b\) and \(c\) is divisible by \(\gcd(a, b)\) (if \(c \neq 0\)), then the answer is YES; otherwise, it is NO.

Note: When \(c = 0\), no water is needed, and the answer should be YES.

inputFormat

The input consists of a single line containing three space-separated integers \(a\), \(b\), and \(c\) where:

  • \(a\): the capacity of the first jug,
  • \(b\): the capacity of the second jug, and
  • \(c\): the target amount of water to measure.

outputFormat

Output a single line containing either YES if it is possible to measure exactly \(c\) liters, or NO otherwise.

## sample
3 5 4
YES

</p>