#K15586. Coin Combination Problem

    ID: 24389 Type: Default 1000ms 256MiB

Coin Combination Problem

Coin Combination Problem

Given two coin denominations (a) and (b) and an amount (k), determine whether it is possible to form exactly (k) using any number (possibly zero) of coins of each denomination. This can be formulated as finding non-negative integers (x) and (y) such that [ a\cdot x + b\cdot y = k, ] which, by the theory of linear Diophantine equations, has an integer solution if and only if (\gcd(a,b)) divides (k). For this problem, you only need to check the divisibility condition: output "YES" if (\gcd(a, b)) divides (k), and "NO" otherwise.

inputFormat

The input is read from standard input (stdin). The first line contains a single integer (T) (the number of test cases). Each of the following (T) lines contains three space-separated integers (a), (b), and (k).

outputFormat

For each test case, print a single line to standard output (stdout) containing "YES" if it is possible to form the amount (k) using coins of denominations (a) and (b), or "NO" if it is not possible.## sample

3
3 5 7
4 6 8
2 6 5
YES

YES NO

</p>