#GL0000158. Bài toán GCD đơn giản (bản dễ) (A Simple GCD Problem (Easy Version))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bài toán GCD đơn giản (bản dễ) (A Simple GCD Problem (Easy Version))
A Simple GCD Problem (Easy Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given arrays and of positive integers. At each position , you may operate at most once: replace by an integer satisfying . In this easy version, at every index.
Let be the resulting array. For every contiguous subarray of length at least two, its GCD must stay equal to the GCD of the corresponding original subarray:
$$\gcd(a_l,\ldots,a_r)=\gcd(a'_l,\ldots,a'_r),\qquad 1\le l<r\le n.$$Find the maximum number of positions you can change. Positions with no operation retain their original values.
Input
The first line contains . The second contains the values of , and the third contains those of .
Output
Print the maximum number of performed operations.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
4
1 2 3 4
1 2 3 4
Output
3
Explanation
All adjacent GCDs in are , so every subarray of length at least two has GCD . Replacing the last three elements by yields and preserves the GCD of every such subarray. The first element cannot be reduced below , so three operations are optimal.