CF1113B.Sasha and Magnetic Machines

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

One day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provided by nn machines, and the power of the ii-th machine is aia_i.

This year 2D decided to cultivate a new culture, but what exactly he didn't say. For the successful growth of the new culture, it is necessary to slightly change the powers of the machines. 2D can at most once choose an arbitrary integer xx, then choose one machine and reduce the power of its machine by xx times, and at the same time increase the power of one another machine by xx times (powers of all the machines must stay positive integers). Note that he may not do that if he wants. More formally, 2D can choose two such indices ii and jj, and one integer xx such that xx is a divisor of aia_i, and change powers as following: ai=aixa_i = \frac{a_i}{x}, aj=aj⋅xa_j = a_j \cdot x

Sasha is very curious, that's why he wants to calculate the minimum total power the farmer can reach. There are too many machines, and Sasha can't cope with computations, help him!

一天,萨沙拜访了农夫2D和他的著名磁力农场。在这个农场上,作物的生长依赖于一种特殊的磁场。该磁场由 nn 台机器维持,第 ii 台机器的功率为 aia_i。

今年,2D 决定培育一种新作物,但他并未透露具体是哪一种。为了使这种新作物成功生长,必须对各台机器的功率进行轻微调整。2D 最多可执行一次如下操作:任选一个整数 xx,再任选一台机器将其功率缩小 xx 倍,同时任选另一台(不同的)机器将其功率增大 xx 倍(所有机器的功率必须始终保持为正整数)。注意:他也可以选择不执行该操作。更形式化地说,2D 可以选择两个下标 ii 和 jj(i≠ji \ne j),以及一个整数 xx,使得 xx 是 aia_i 的约数,并按如下方式更新功率:ai=aixa_i = \frac{a_i}{x},aj=aj⋅xa_j = a_j \cdot x。

萨沙非常好奇,因此他想计算农夫所能达到的最小总功率。机器数量太多,萨沙无法独立完成计算,请你帮助他!

输入格式

The first line contains one integer nn (2≤n≤5⋅1042 \le n \le 5 \cdot 10^4) — the number of machines.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1001 \le a_i \le 100) — the powers of the machines.

第一行包含一个整数 nn(2≤n≤5⋅1042 \le n \le 5 \cdot 10^4)——机器的数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1001 \le a_i \le 100)——各台机器的功率。

输出格式

Print one integer — minimum total power.

输出一个整数——最小总能量。

输入输出样例

  • 输入#1

    5
    1 2 3 4 5

    输出#1

    14
  • 输入#2

    4
    4 2 4 4

    输出#2

    14
  • 输入#3

    5
    2 4 2 3 7

    输出#3

    18

说明/提示

In the first example, the farmer can reduce the power of the 44-th machine by 22 times, and increase the power of the 11-st machine by 22 times, then the powers will be: [2,2,3,2,5][2, 2, 3, 2, 5].

In the second example, the farmer can reduce the power of the 33-rd machine by 22 times, and increase the power of the 22-nd machine by 22 times. At the same time, the farmer can leave is be as it is and the total power won't change.

In the third example, it is optimal to leave it be as it is.

在第一个例子中,农民可以将第 44 台机器的功率降低为原来的 12\frac{1}{2},并将第 11 台机器的功率提升为原来的 22 倍,此时各台机器的功率变为:[2,2,3,2,5][2, 2, 3, 2, 5]。

在第二个例子中,农民可以将第 33 台机器的功率降低为原来的 12\frac{1}{2},并将第 22 台机器的功率提升为原来的 22 倍。同时,农民也可以选择不做任何操作,此时总功率保持不变。

在第三个例子中,最优策略是不做任何操作。

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

首页