Codeforces Round 1060 (Div. 2)
C1
No Cost Too Great (Easy Version)
Codeforces
1400
原题
← BC2 →
翻译中…

This is the easy version of the problem. The difference between the versions is that in this version, $b_i = 1$ for all $i$ ($1 \le i \le n$). You can hack only if you solved all versions of this problem.

翻译中…

You find yourself with two arrays of positive integers $a$ and $b$, both of length $n$. You will perform the following operation any number of times (possibly none):

翻译中…
  • select an integer $i$ ($1 \le i \le n$) and increase $a_i$ by $1$. This has a cost of $b_i$.
翻译中…

Determine the minimum total cost to make it so that there exists two integers $i, j$ where $1 \le i \lt j \le n$ and $\gcd(a_i, a_j)$$^{\text{∗}}$$ \gt 1$.

翻译中…

$^{\text{∗}}$$\gcd(x, y)$ denotes the greatest common divisor (GCD) of integers $x$ and $y$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains an integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the length of the array $a$.

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le 2 \cdot 10^5$).

翻译中…

The third line of each test case contains $n$ integers $b_1,b_2,\ldots,b_n$ ($\color{red}{b_i = 1}$).

翻译中…

The sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each testcase, output the minimum cost.

翻译中…

Note

翻译中…

In the first test case, we can do the following: $[\color{red}1, 1] \xrightarrow{x = 1} [2, \color{red}1] \xrightarrow{x = 2} [2, 2]$. Now $\gcd(a_1, a_2) = \gcd(2, 2) = 2$ and so $\gcd(a_1, a_2) \gt 1$. It can be proven that this is the minimum cost required.

翻译中…

In the second test case, it is already true that $\gcd(a_1, a_2) = 4$ and so $\gcd(a_1, a_2) \gt 1$. So no operations are required.

翻译中…

样例

Input #1
6
2
1 1
1 1
2
4 8
1 1
5
1 1 727 1 1
1 1 1 1 1
2
3 11
1 1
3
2 7 11
1 1 1
3
7 12 13
1 1 1
Output #1
2
0
2
1
1
1
InputCopy OutputCopy
题目信息
题号
2154C1
时间限制
3 s
内存限制
256 MB
标签
贪心
模拟
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。