Sometimes, competitive programming questions whose outputs are rational numbers qp ask you to output the quantity pq−1modm instead, for some prime modulus m. However, this quantity is difficult to debug when your program is giving you the wrong answer because calculating q−1 is difficult to do by hand and the magnitude of the quantity can be very large for small rationals. For example, 1⋅2−1mod97=49.
To debug your solution quickly, you want to create a program that given pq−1modm recovers the values of p and q. The possible values for p and q are not unique, but to help you narrow it down, you know that qp (interpreted as an ordinary rational number) is in the range \[x,x+1) for some integer x.
Given the three values v, x, and m, find the minimum possible p and corresponding q such that (0≤p,q<m) pq−1≡vmodm and x≤qp<x+1.
The input is a single line with three space-separated integers v, x, and m, where 3≤m≤106, 1≤v<m, 0≤x<m, and m is prime.
Print the minimal integer p and the corresponding q such that 0≤p,q<m, pq−1≡vmodm, and x≤qp<x+1. If there are multiple such p and q, print the pair with the minimum value of p. If no such p and q exist, then print a single −1 instead.