Modular Reverse Engineering

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Sometimes, competitive programming questions whose outputs are rational numbers pq\frac{p}{q} ask you to output the quantity pq1modmpq^{-1} \bmod m instead, for some prime modulus mm. However, this quantity is difficult to debug when your program is giving you the wrong answer because calculating q1q^{-1} is difficult to do by hand and the magnitude of the quantity can be very large for small rationals. For example, 121mod97=491 \cdot 2^{-1} \bmod 97 = 49.

To debug your solution quickly, you want to create a program that given pq1modmpq^{-1} \bmod m recovers the values of pp and qq. The possible values for pp and qq are not unique, but to help you narrow it down, you know that pq\frac{p}{q} (interpreted as an ordinary rational number) is in the range \[x,x+1)\[x, x + 1) for some integer xx.

Given the three values vv, xx, and mm, find the minimum possible pp and corresponding qq such that (0p,q<m0 \leq p, q < m) pq1vmodmpq^{-1} \equiv v \bmod m and xpq<x+1x \leq \frac{p}{q} < x + 1.

입력

The input is a single line with three space-separated integers vv, xx, and mm, where 3m1063 \leq m \leq 10^6, 1v<m1 \leq v < m, 0x<m0 \leq x < m, and mm is prime.

출력

Print the minimal integer pp and the corresponding qq such that 0p,q<m0 \leq p,q < m, pq1vmodmpq^{-1} \equiv v \bmod m, and xpq<x+1x \leq \frac{p}{q} < x + 1. If there are multiple such pp and qq, print the pair with the minimum value of pp. If no such pp and qq exist, then print a single 1-1 instead.