HUST Past Monthly Hard Problems Challenge Contest (1)

From: 2011-05-13 12:00:00 To: 2011-05-13 17:00:00 Now: 2017-09-20 01:07:59 Status: Public

I - Minimum Power

Time Limit: 1s Memory Limit: 128MB

Submissions: 198 Solved: 65
Description
Mike is learning number theory recently, and he has found a beautiful formula: . Now given A, N, Z, can you find minimum nonnegative L that satisfies the formula?
Input
First line a integer T indicating the number of the test cases. Next T line, each line contains three integers A, N, Z, refer to the description. Note that Z may not be a prime ( 0 <= A , N <= 2,147,483,647 ), ( 2 <= Z <= 2,147,483,647 )
Output
For each test case output one line. Write “No Solution” if you cannot find a feasible L(0 <= L < Z), otherwise output the minimum L you find.
Sample Input
2
5 33 58
2 3 4
Sample Output
9
No Solution
Hint
Source