Not Adding

 1 Sec 256 MB |  Markdown 获取标签

 

题目描述

你有一个长度为 nn 的数组 a1,a2,,ana_1,a_2,\dots,a_n,每次操作你可以选择数组中的两个元素 ai,aja_i,a_j需要保证 gcd{ai,aj}\gcd{a_i,a_j} 不在原数组内),然后将 gcd{ai,aj}\gcd{a_i,a_j} 放到数组末尾。求你最多能够对这个数组进行多少次操作。

输入格式

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

The second line consists of nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1061 \leq a_i \leq 10^6). All aia_i are distinct.

输出格式

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

样例输入 #1

5
4 20 1 25 30

样例输出 #1

3

样例输入 #2

3
6 10 15

样例输出 #2

4

提示

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

  • Pick i=1,j=5 i = 1, j= 5 and add gcd(a1,a5)=gcd(4,30)=2 \gcd(a_1, a_5) = \gcd(4, 30) = 2 to the array.
  • Pick i=2,j=4 i = 2, j= 4 and add gcd(a2,a4)=gcd(20,25)=5 \gcd(a_2, a_4) = \gcd(20, 25) = 5 to the array.
  • Pick i=2,j=5 i = 2, j= 5 and add gcd(a2,a5)=gcd(20,30)=10 \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 3 operations on the original array.

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

来源

CF766-D

 

 您尚未登录,无法进行代码提交

ACM协会第七次培训(素数筛)

2024-11-30 21:18
2024-12-08 22:00
Ended