AT_abc474_f.Increment All Divisors
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a length-N integer sequence A=(A1,A2,…,AN).
You can perform the following operation on A any number of times.
- Choose an integer i with 1≤i≤N. For every integer j that is a positive divisor of i, add 1 to Aj.
Determine whether it is possible to make all elements of A equal, and if it is possible, find the minimum number of operations required to do so.
给你一个长度为 N 的整数序列 A=(A1,A2,…,AN)。
你可以对 A 执行以下操作任意多次:
- 选择一个整数 i,满足 1≤i≤N;对每个能整除 i 的正整数 j,将 Aj 加 1。
判断是否可能使 A 的所有元素相等;若可能,求出实现该目标所需的最少操作次数。
输入格式
The input is given from Standard Input in the following format:
N
A1 A2 … AN
输入从标准输入中按以下格式给出:
N
A1 A2 … AN
输出格式
If it is possible to make all elements of A equal, output, in one line, the minimum number of operations required to do so; otherwise, output −1.
如果可以使数组 A 的所有元素相等,则输出使其全部相等所需的最少操作次数(在一行内);否则,输出 −1。
输入输出样例
输入#1
3 4 7 4
输出#1
3
输入#2
5 1 3 4 5 6
输出#2
5
输入#3
2 5 2
输出#3
-1
说明/提示
Sample 1 Explanation:
If you choose i=3 for the first operation, you get A=(5,7,5).
If you choose i=3 for the second operation, you get A=(6,7,6).
If you choose i=3 for the third operation, you get A=(7,7,7).
It is impossible to make all elements of A equal with fewer than three operations, so the answer is 3.
Constraints
- 1≤N≤2×105
- 1≤Ai≤109
- All input values are integers.
样例 1 解释:
若第一次操作选择 i=3,则得到 A=(5,7,5)。
若第二次操作选择 i=3,则得到 A=(6,7,6)。
若第三次操作选择 i=3,则得到 A=(7,7,7)。
无法用少于三次操作使数组 A 的所有元素相等,因此答案为 3。
限制条件
- 1≤N≤2×105
- 1≤Ai≤109
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?