Hide

Problem B
Pohlig-Hellman

Languages en is

Implement the Pohlig-Hellman algorithm to solve gxh(modp) for x.

Input

Input is three lines. The first line contains the prime p where 3p<263 and each prime factor of p1 are less than 240. The second line contains the integer g where 2g<p of order at least 2. The third line contains the integer h where 0h<p.

Output

Output one line with any valid solution 0x<p1 or no solution if no solution exists.

Sample Input 1 Sample Output 1
3
2
1
0
Sample Input 2 Sample Output 2
449
6
99
182
Sample Input 3 Sample Output 3
7
4
3
no solution
Hide

Please log in to submit a solution to this problem

Log in