AT_abc474_f.Increment All Divisors

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a length-NN integer sequence A=(A1,A2,…,AN)A=(A_1,A_2,\dots,A_N).
You can perform the following operation on AA any number of times.

  • Choose an integer ii with 1≤i≤N1 \leq i \leq N. For every integer jj that is a positive divisor of ii, add 11 to AjA_j.

Determine whether it is possible to make all elements of AA equal, and if it is possible, find the minimum number of operations required to do so.

给你一个长度为 NN 的整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\dots,A_N)。
你可以对 AA 执行以下操作任意多次:

  • 选择一个整数 ii,满足 1≤i≤N1 \leq i \leq N;对每个能整除 ii 的正整数 jj,将 AjA_j 加 11。

判断是否可能使 AA 的所有元素相等;若可能,求出实现该目标所需的最少操作次数。

输入格式

The input is given from Standard Input in the following format:

NN
A1A_1 A2A_2 …\ldots ANA_N

输入从标准输入中按以下格式给出:

NN
A1A_1 A2A_2 …\ldots ANA_N

输出格式

If it is possible to make all elements of AA equal, output, in one line, the minimum number of operations required to do so; otherwise, output −1-1.

如果可以使数组 AA 的所有元素相等,则输出使其全部相等所需的最少操作次数(在一行内);否则,输出 −1-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=3i=3 for the first operation, you get A=(5,7,5)A=(5,7,5).
If you choose i=3i=3 for the second operation, you get A=(6,7,6)A=(6,7,6).
If you choose i=3i=3 for the third operation, you get A=(7,7,7)A=(7,7,7).
It is impossible to make all elements of AA equal with fewer than three operations, so the answer is 33.

Constraints

  • 1≤N≤2×1051 \leq N \leq 2 \times 10^5
  • 1≤Ai≤1091 \leq A_i \leq 10^9
  • All input values are integers.

样例 1 解释:
若第一次操作选择 i=3i=3,则得到 A=(5,7,5)A=(5,7,5)。
若第二次操作选择 i=3i=3,则得到 A=(6,7,6)A=(6,7,6)。
若第三次操作选择 i=3i=3,则得到 A=(7,7,7)A=(7,7,7)。
无法用少于三次操作使数组 AA 的所有元素相等,因此答案为 33。

限制条件

  • 1≤N≤2×1051 \leq N \leq 2 \times 10^5
  • 1≤Ai≤1091 \leq A_i \leq 10^9
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页