Ivan the Terrible P36895


Statement
 

pdf   zip

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.

Public test cases
  • Input

    7
    2 1 0
    7 3 6
    8 3 6
    6 0 5
    6 0 1
    1000000000 42424242 1
    1000000000 123456789 987654320
    

    Output

    NO
    YES
    NO
    NO
    YES
    YES
    NO
    
  • Information
    Author
    Ivan Geffner
    Language
    English
    Official solutions
    C++
    User solutions
    C++