CF1034A.Enlarge GCD
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Mr. F has n positive integers, a1,a2,…,an.
He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers.
But this problem is too simple for him, so he does not want to do it by himself. If you help him, he will give you some scores in reward.
Your task is to calculate the minimum number of integers you need to remove so that the greatest common divisor of the remaining integers is bigger than that of all integers.
F 先生有 n 个正整数:a1,a2,…,an。
他认为这些整数的最大公约数(GCD)太小了,因此希望通过删除其中一部分整数来增大该最大公约数。
但这个问题对他而言过于简单,所以他不想自己动手解决。如果你帮助他解决,他将给予你一些分数作为奖励。
你的任务是:计算需要删除的最少整数个数,使得剩余整数的最大公约数严格大于原始所有 n 个整数的最大公约数。
输入格式
The first line contains an integer n (2≤n≤3⋅105) — the number of integers Mr. F has.
The second line contains n integers, a1,a2,…,an (1≤ai≤1.5⋅107).
第一行包含一个整数 n(2≤n≤3⋅105)—— 表示 Mr. F 拥有的整数个数。
第二行包含 n 个整数:a1,a2,…,an(1≤ai≤1.5⋅107)。
输出格式
Print an integer — the minimum number of integers you need to remove so that the greatest common divisor of the remaining integers is bigger than that of all integers.
You should not remove all of the integers.
If there is no solution, print «-1» (without quotes).
输出一个整数——为使剩余整数的最大公约数(GCD)大于所有整数的最大公约数,所需移除的最少整数个数。
你不应移除全部整数。
若无解,则输出 «-1»(不带引号)。
输入输出样例
输入#1
3 1 2 4
输出#1
1
输入#2
4 6 9 15 30
输出#2
2
输入#3
3 1 1 1
输出#3
-1
说明/提示
In the first example, the greatest common divisor is 1 in the beginning. You can remove 1 so that the greatest common divisor is enlarged to 2. The answer is 1.
In the second example, the greatest common divisor is 3 in the beginning. You can remove 6 and 9 so that the greatest common divisor is enlarged to 15. There is no solution which removes only one integer. So the answer is 2.
In the third example, there is no solution to enlarge the greatest common divisor. So the answer is −1.
在第一个例子中,初始的最大公约数为 1。你可以移除 1,使得最大公约数扩大至 2。答案为 1。
在第二个例子中,初始的最大公约数为 3。你可以移除 6 和 9,使得最大公约数扩大至 15。不存在仅移除一个整数的解。因此答案为 2。
在第三个例子中,不存在能使最大公约数扩大的解。因此答案为 −1。
输入解题思路,AI测评打分。不知道怎么写?