#K93922. Modular Inverse Existence Checker

    ID: 38527 Type: Default 1000ms 256MiB

Modular Inverse Existence Checker

Modular Inverse Existence Checker

You are given three integers A, Y, and M in each test case. Your task is to determine whether the linear congruence equation

\(A \times X \equiv Y \pmod{M}\)

has a solution. In this problem, a solution is considered to exist if and only if the modular inverse of A modulo M exists, which is true if and only if \(\gcd(A, M) = 1\). Note that the value of Y does not affect the existence of a modular inverse.

For each test case, print YES if A and M are coprime (i.e. the modular inverse exists) or NO otherwise.

inputFormat

The first line of input contains an integer T representing the number of test cases. Each of the next T lines contains three integers A, Y, and M separated by spaces.

Note: Even though Y is provided as part of the input, the result depends solely on whether A and M are coprime.

outputFormat

For each test case, output a single line containing YES if the modular inverse of A modulo M exists, otherwise output NO.

## sample
3
5 3 7
4 10 11
2 2 4
YES

YES NO

</p>