CF2210C1.A Simple GCD Problem (Easy Version)

普及-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the easy version of the problem. The difference between the versions is that in this version, $ 1 \leq n \leq 2 \cdot 10^{5} $ and $ b_i = a_i $ for $ 1 \leq i \leq n $ . Note that a solution for one version does not necessarily solve the other version. You can hack only if you solved all versions of this problem.

You are given two arrays $ a $ and $ b $ of length $ n $ .

For each index $ i $ ( $ 1 \le i \le n $ ) of array $ a $ , you can perform the following operation at most once:

  • choose an arbitrary integer $ m $ ( $ \mathbf{m \neq a_i} $ ) such that $ 1 \leq m \le b_i $ , and set $ a_i := m $ .

Let the array after performing all the operations be $ a' $ . You can only perform operations in such a way that the following condition holds:

  • for all $ 1\leq l \lt r\leq n $ , $ \operatorname{gcd}(a_l,a_{l+1},\ldots,{a_r})=\operatorname{gcd}(a'l,a'{l+1},\ldots,a'_r). $

Here, $ \gcd(x, y) $ denotes the greatest common divisor (GCD) of integers $ x $ and $ y $ .

You have to determine the maximum number of operations that can be performed while ensuring that the condition remains satisfied.

输入格式

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 \leq n \leq 2\cdot 10^5 $ ) — the length of $ a $ .

The following line of each test case contains $ n $ space-separated integers $ a_1, a_2, \ldots, a_n $ ( $ 1 \leq a_i \leq 10^9 $ ).

The next line of each test case contains $ n $ space-separated integers $ b_1, b_2, \ldots, b_n $ ( $ \color{red}{b_i = a_i} $ ).

It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2\cdot10^5 $ .

输出格式

For each test case, output the maximum number of operations that can be done on a newline.

输入输出样例

  • 输入#1

    4
    7
    1 2 3 4 5 6 7
    1 2 3 4 5 6 7
    3
    67 67 67
    67 67 67
    6
    8 10 10 12 12 14
    8 10 10 12 12 14
    8
    2 4 8 16 32 64 128 256
    2 4 8 16 32 64 128 256

    输出#1

    6
    0
    2
    1

说明/提示

For the first test case, the GCD of all subarrays is $ 1 $ . Hence, we can perform $ 6 $ operations and change the array to $ a' = [1, 1, 1, 1, 1, 1, 1] $ . It can be shown that the maximum number of operations that can be performed in this case is $ 6 $ .

For the second test case, note that all the values are equal, and reducing any value causes the GCD of subarrays to decrease. Hence, $ 0 $ operations can be performed.

For the third test case, it can be shown that at most $ 2 $ operations can be performed.

输入解题思路,AI测评打分。不知道怎么写?

首页