Codeforces Round 766 (Div. 2)
D
Not Adding
Codeforces
1900
原题
← CE →
翻译中…

You have an array $a_1, a_2, \dots, a_n$ consisting of $n$ distinct integers. You are allowed to perform the following operation on it:

翻译中…
  • Choose two elements from the array $a_i$ and $a_j$ ($i \ne j$) such that $\gcd(a_i, a_j)$ is not present in the array, and add $\gcd(a_i, a_j)$ to the end of the array. Here $\gcd(x, y)$ denotes greatest common divisor (GCD) of integers $x$ and $y$.
翻译中…

Note that the array changes after each operation, and the subsequent operations are performed on the new array.

翻译中…

What is the maximum number of times you can perform the operation on the array?

翻译中…

Input

翻译中…

The first line consists of a single integer $n$ ($2 \le n \le 10^6$).

翻译中…

The second line consists of $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^6$). All $a_i$ are distinct.

翻译中…

Output

翻译中…

Output a single line containing one integer — the maximum number of times the operation can be performed on the given array.

翻译中…

Note

翻译中…

In the first example, one of the ways to perform maximum number of operations on the array is:

翻译中…
  • Pick $i = 1, j= 5$ and add $\gcd(a_1, a_5) = \gcd(4, 30) = 2$ to the array.
  • Pick $i = 2, j= 4$ and add $\gcd(a_2, a_4) = \gcd(20, 25) = 5$ to the array.
  • Pick $i = 2, j= 5$ and add $\gcd(a_2, a_5) = \gcd(20, 30) = 10$ to the array.
翻译中…

It can be proved that there is no way to perform more than $3$ operations on the original array.

翻译中…

In the second example one can add $3$, then $1$, then $5$, and $2$.

翻译中…

样例

Input #1
5
4 20 1 25 30
Output #1
3
InputCopy OutputCopy
Input #2
3
6 10 15
Output #2
4
InputCopy OutputCopy
题目信息
题号
1627D
时间限制
2 s
内存限制
256 MB
标签
暴力
动态规划
数学
数论

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