#P7706. [2019年杭电多校]discrete logarithm problem
[2019年杭电多校]discrete logarithm problem
discrete logarithm problem
Problem Description
You are given three integers , where is a prime number and only has prime factors and/or . Please find the minimum positive integer such that .
Input
The first line contains an integer indicating there are tests. Each test consists of a single line containing three integers: .
- the prime factors of can only be or
Output
For each test, output a line containing an integer , representing the minimum positive value such that . If there didn't exist any such number , please output .
Sample Input
6
65537 2 3
65537 2 4
65537 3 4
65537 4 4
65537 5 4
666334875701477377 2 3
Sample Output
-1
2
45056
1
36864
1957714645490451
Source
2019 Multi-University Training Contest 5