| 2025 GUC Winter Camp |
|---|
| Закончено |
You are given two arrays $$$a$$$ and $$$b$$$, each of length $$$n$$$ ($$$1 \le n \le 5000$$$). You may perform the following operation any number of times (indices are 1-based):
Your task is to compute the minimum total cost required to make the gcd of all elements of array $$$a$$$ equal to $$$1$$$. If it is impossible to achieve $$$\gcd(a[1], a[2], \ldots, a[n]) = 1$$$ by any sequence of operations, print $$$-1$$$.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 5000$$$).
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a[i] \le 10^{12}$$$).
The third line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b[i] \le 10^{12}$$$).
Print a single integer — the minimum total cost to make $$$\gcd(a_1, a_2, \ldots, a_n) = 1$$$, or $$$-1$$$ if it is impossible.
26 103 7
2
36 30 605 10 21
2
| Название |
|---|


