eolymp
bolt
Try our new interface for solving problems
Problems

Interesting equation

Interesting equation

Little \textbf{Y} finds there is a very interesting formula in mathematics: \textbf{X^Y mod Z = K} Given \textbf{X}, \textbf{Y}, \textbf{Z}, we all know how to figure out \textbf{K} fast. However, given \textbf{X}, \textbf{Z}, \textbf{K}, could you figure out \textbf{Y} fast? \InputFile Input data consists of no more than \textbf{20} test cases. For each test case, there would be only one line containing \textbf{3} integers \textit{\textbf{X}}, \textbf{Z}, \textbf{K} (\textbf{0} ≤ \textbf{X}, \textbf{Z}, \textbf{K} ≤ \textbf{10^9}). \OutputFile For each test case output one line. Write "\textbf{No Solution}" (without quotes) if you cannot find a feasible \textbf{Y} (\textbf{0} ≤ \textbf{Y} < \textbf{Z}). Otherwise output the minimum \textbf{Y} you find.
Time limit 5 seconds
Memory limit 64 MiB
Input example #1
2
5 58 33
2 4 3
Output example #1
9
No Solution
Source POJ Monthly - 2007.07.08, Guo, Huayang