codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

2154C1.md (2184B)


      1 Source: https://codeforces.com/problemset/problem/2154/C1
      2 
      3 C1. No Cost Too Great (Easy Version)
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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):
     24 
     25 * select an integer $i$ ($1 \le i \le n$) and increase $a_i$ by $1$. This has a cost of $b_i$.
     26 
     27 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$.
     28 
     29 $^{\text{∗}}$$\gcd(x, y)$ denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers $x$ and $y$.
     30 
     31 Input
     32 
     33 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.
     34 
     35 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$.
     36 
     37 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$).
     38 
     39 The third line of each test case contains $n$ integers $b_1,b_2,\ldots,b_n$ ($\color{red}{b_i = 1}$).
     40 
     41 The sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.
     42 
     43 Output
     44 
     45 For each testcase, output the minimum cost.
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 6
     53 
     54 2
     55 
     56 1 1
     57 
     58 1 1
     59 
     60 2
     61 
     62 4 8
     63 
     64 1 1
     65 
     66 5
     67 
     68 1 1 727 1 1
     69 
     70 1 1 1 1 1
     71 
     72 2
     73 
     74 3 11
     75 
     76 1 1
     77 
     78 3
     79 
     80 2 7 11
     81 
     82 1 1 1
     83 
     84 3
     85 
     86 7 12 13
     87 
     88 1 1 1
     89 ```
     90 
     91 Output
     92 
     93 ```
     94 2
     95 
     96 0
     97 
     98 2
     99 
    100 1
    101 
    102 1
    103 
    104 1
    105 ```
    106 
    107 Note
    108 
    109 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.
    110 
    111 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.