#P4777. 【模板】扩展中国剩余定理(EXCRT)
【模板】扩展中国剩余定理(EXCRT)
Description
Given pairs of non-negative integers , find the smallest non-negative integer solution to the system of equations in .
$$\begin{cases}x\equiv b_1\pmod{a_1}\\x\equiv b_2\pmod{a_2}\\\dots\\x\equiv b_n\pmod{a_n}\end{cases}$$Input Format
The first line contains an integer .
The next lines each contain two non-negative integers .
Output Format
Output one line: the smallest non-negative integer that satisfies the conditions.
3
11 6
25 9
33 17
809
Hint
For of the testdata, , , . It is guaranteed that the least common multiple of all does not exceed .
Please note that during the execution of the program, multiplication operations may overflow.
It is guaranteed that a solution exists.
Translated by ChatGPT 5
京公网安备 11011102002149号