CF1614D1.Divan and Kostomuksha (easy version)

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The only difference is maximum value of aia_i.

Once in Kostomuksha Divan found an array aa consisting of positive integers. Now he wants to reorder the elements of aa to maximize the value of the following function:

i=1ngcd(a1,a2,,ai),\sum_{i=1}^n \operatorname{gcd}(a_1, \, a_2, \, \dots, \, a_i),

where gcd(x1,x2,,xk)\operatorname{gcd}(x_1, x_2, \ldots, x_k) denotes the greatest common divisor of integers x1,x2,,xkx_1, x_2, \ldots, x_k , and gcd(x)=x\operatorname{gcd}(x) = x for any integer xx.

Reordering elements of an array means changing the order of elements in the array arbitrary, or leaving the initial order.

Of course, Divan can solve this problem. However, he found it interesting, so he decided to share it with you.

输入格式

The first line contains a single integer nn ( 1n1051 \leq n \leq 10^5 ) — the size of the array aa .

The second line contains nn integers a1,a2,,ana_{1}, \, a_{2}, \, \dots, \, a_{n} ( 1ai51061 \le a_{i} \le 5 \cdot 10^6 ) — the array aa .

输出格式

Output the maximum value of the function that you can get by reordering elements of the array aa .

输入输出样例

  • 输入#1

    6
    2 3 1 2 6 2

    输出#1

    14
  • 输入#2

    10
    5 7 10 3 1 10 100 3 42 54

    输出#2

    131

说明/提示

In the first example, it's optimal to rearrange the elements of the given array in the following order: [6,2,2,2,3,1][6, \, 2, \, 2, \, 2, \, 3, \, 1] :

gcd(a1)+gcd(a1,a2)+gcd(a1,a2,a3)+gcd(a1,a2,a3,a4)+gcd(a1,a2,a3,a4,a5)+gcd(a1,a2,a3,a4,a5,a6)=6+2+2+2+1+1=14.\operatorname{gcd}(a_1) + \operatorname{gcd}(a_1, \, a_2) + \operatorname{gcd}(a_1, \, a_2, \, a_3) + \operatorname{gcd}(a_1, \, a_2, \, a_3, \, a_4)\\ + \operatorname{gcd}(a_1, \, a_2, \, a_3, \, a_4, \, a_5) + \operatorname{gcd}(a_1, \, a_2, \, a_3, \, a_4, \, a_5, \, a_6)\\= 6 + 2 + 2 + 2 + 1 + 1 = 14.

It can be shown that it is impossible to get a better answer.

In the second example, it's optimal to rearrange the elements of a given array in the following order: [100,10,10,5,1,3,3,7,42,54][100, \, 10, \, 10, \, 5, \, 1, \, 3, \, 3, \, 7, \, 42, \, 54].

首页