F. 将所有约数加一 / Increment All Divisors

    传统题 2000ms 256MiB

将所有约数加一 / Increment All Divisors

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Statement

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.

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.

Input

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

  • NN
  • A1A_1 A2A_2 …\dots ANA_N

Output

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.

3
4 7 4
3

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.

5
1 3 4 5 6
5
2
5 2
-1

ABC474 赛后模拟赛 ✅

未参加
状态
已结束
规则
IOI
题目
7
开始于
2026-9-6 14:00
结束于
2026-9-20 14:00
持续时间
336 小时
主持人
参赛人数
59