CF1627D.Not Adding
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have an array a1,a2,…,an consisting of n distinct integers. You are allowed to perform the following operation on it:
- Choose two elements from the array ai and aj (i=j) such that gcd(ai,aj) is not present in the array, and add gcd(ai,aj) 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?
你有一个由 n 个互不相同的整数组成的数组 a1,a2,…,an。你可以对它执行如下操作:
- 从数组中选择两个元素 ai 和 aj(其中 i=j),满足 gcd(ai,aj) 不在当前数组中,并将 gcd(ai,aj) 添加到数组末尾。这里 gcd(x,y) 表示整数 x 与 y 的最大公约数(GCD)。
注意:每次操作后数组都会发生变化,后续操作均在更新后的数组上进行。
你最多能对该数组执行多少次该操作?
输入格式
The first line consists of a single integer n (2≤n≤106).
The second line consists of n integers a1,a2,…,an (1≤ai≤106). All ai are distinct.
第一行包含一个整数 n(2≤n≤106)。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤106)。所有 ai 互不相同。
输出格式
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 and add gcd(a1,a5)=gcd(4,30)=2 to the array.
- Pick i=2,j=4 and add gcd(a2,a4)=gcd(20,25)=5 to the array.
- Pick i=2,j=5 and add gcd(a2,a5)=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.
在第一个例子中,对数组执行最多次数操作的一种方法是:
- 选取 i=1,j=5,并将 gcd(a1,a5)=gcd(4,30)=2 加入数组。
- 选取 i=2,j=4,并将 gcd(a2,a4)=gcd(20,25)=5 加入数组。
- 选取 i=2,j=5,并将 gcd(a2,a5)=gcd(20,30)=10 加入数组。
可以证明:无法对原始数组执行超过 3 次操作。
在第二个例子中,可以依次加入 3、1、5 和 2。
输入解题思路,AI测评打分。不知道怎么写?