Ivan the Terrible

Given three integer numbers nn, aa and bb, does there exist a natural tt such that atbmodna^t \equiv b \bmod n?

Input

Input consists of the number of cases cc, followed by cc triples with nn, aa and bb. You can assume 2n1092 \le n \le 10^9, 0a<n0 \le a < n, and 0b<n0 \le b < n. Additionally, assume c200c \le 200 for the “hard private test cases”.

Output

For each case, print “YES” or “NO” depending on whether atbmodna^t \equiv b \bmod n has at least one solution t0t \ge 0 or not.

Problem information

Author: Ivan Geffner

Generation: 2026-01-25T10:31:11.350Z

© Jutge.org, 2006–2026.
https://jutge.org