#P3868. [TJOI2009] 猜数字

    ID: 2806 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数学2009各省省选扩展欧几里德,扩欧中国剩余定理,CRT天津

[TJOI2009] 猜数字

Description

There are two groups of numbers, each with kk elements.

The numbers in the first group are denoted by a1,a2,,aka_1,a_2,\cdots ,a_k, and the numbers in the second group are denoted by b1,b2,,bkb_1,b_2,\cdots ,b_k.

The numbers in the second group are pairwise coprime. Find the smallest nNn\in \mathbb{N} such that for i[1,k]\forall i\in [1,k], bi(nai)b_i | (n-a_i) holds.

Input Format

The first line contains an integer kk.

The second line contains kk integers: a1,a2,,aka_1,a_2,\cdots ,a_k.

The third line contains kk integers: b1,b2,,bkb_1,b_2,\cdots ,b_k.

Output Format

Output a single integer, which is the required answer nn.

3
1 2 3
2 3 5

23

Hint

Constraints:

1k101\le k \le 10ai109|a_i|\le 10^91bi6×1031\le b_i\le 6\times 10^3i=1kbi1018\prod_{i=1}^k b_i\le 10^{18}.

Time limit per test case: 1 second.

Note: For C/C++ language, 64-bit integers should be declared as long long.

If using scanf and printf (as well as fscanf, fprintf, etc.), use the %lld specifier.

Translated by ChatGPT 5