#P9879. Congruences
Congruences
Congruences
Problem Description
Your task is to solve a system of congruences, each one represented in the following format:
$$x ^ {p_i} \equiv q_i \pmod n \quad (i = 1, 2, ..., m) $$Here, refers to pairwise distinct prime numbers, is the product of all (i.e., ), and is an integer within the range of . The goal is to find the smallest positive integer that fulfills all given congruences. If there is no solution exists for the given system of congruences, output .
Input
The first line contains a positive integer (), indicating the number of test cases. For each test case, the first line contains a positive integer , and each of the following lines contains two integers and (, ). It is guaranteed that .
Output
For each test case, output a single positive integer representing the answer or output .
Sample Input
3
2
3 5
2 1
1
13 3
2
3 4
2 4
Sample Output
5
3
4
Hint
You can use __int128 in your C++ code.
Source
2023“钉耙编程”中国大学生算法设计超级联赛(8)