Divan and Kostomuksha (easy version)

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

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

∑i=1ngcd⁡(a1,a2,…,ai),

where gcd⁡(x1,x2,…,xk) denotes the greatest common divisor of integers x1,x2,…,xk, and gcd⁡(x)=x for any integer x.

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.

Input

The first line contains a single integer n (1≤n≤105) — the size of the array a.

The second line contains n integers a1,a2,…,an (1≤ai≤5⋅106) — the array a.

Output

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

Examples

input

Copy

6
2 3 1 2 6 2

output

Copy

14

input

Copy

10
5 7 10 3 1 10 100 3 42 54

output

Copy

131

Note

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]:

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.

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].

思路:这个题要求最大公约数的和,我们可以将公约数转化为公倍数的问题。那么接着下一步,我们可以记录下数组每个数的倍数在数组出现多少次,(也就是说明有多少个数又同一个约数),这里我们用cnt[](数组)来记录每个数出现的次数,然后我们不是可以将每个数的倍数个数记录在cnt中,cnt[j]=x,说明以j为因数出现了x次,那么最难的问题来了,我们要怎样以倍数来表示公约数呢?我们先造一下样例:2 2 2 3 3 3 4 4 4,cnt[2]=6,cnt[3]=3,cnt[4]=3,最大公约数和为4+4+4+2+2+2+1+1+1=4*3+2*3+3=2*(2*3+3)+3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值