问题 C: Congruences

内存限制:256 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Your task is to solve a system of m congruences, each one represented in the following format:

xpiqi(modn)(i=1,2,...,m)

Here,pi refers to pairwise distinct prime numbers, n is the product of all pi (i.e., n=i=1mpi), and qi is an integer within the range of [0,n).

The goal is to find the smallest positive integer x that fulfills all given congruences. If there is no solution exists for the given system of congruences, output −11.

输入格式

The first line contains a positive integer T (1T104), indicating the number of test cases.

For each test case, the first line contains a positive integer m, and each of the following m lines contains two integers pi and qi (2pi10180qi<n). It is guaranteed that n=i=1mpi1018.

输出格式

For each test case, output a single positive integer x representing the answer or output −11.

输入样例 复制

3
2
3 5
2 1
1
13 3
2
3 4
2 4

输出样例 复制

5
3
4

数据范围与提示

You can use __int128 in your C++ code

分类标签