A1-2017级算法上机第一次练习赛 P ModricWang's Number Theory II

Posted zjsyzmx0527

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A1-2017级算法上机第一次练习赛 P ModricWang's Number Theory II相关的知识,希望对你有一定的参考价值。

题目描述

ModricWang has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1.

ModricWang can perform two types of operations:

  • Choose a number and delete it with cost x.
  • Choose a number and increase it by 1 with cost y.

ModricWang can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.

Help ModricWang to find the minimum possible cost to make the list good.

输入

First line contains three integers n,xn,x and y(1?≤?n?≤?5?105,1?≤x,?y?≤?109)y(1?≤?n?≤?5·105,1?≤x,?y?≤?109) — the number of elements in the list and the integers x and y.

Second line contains n integers a1,?a2,?...,?an(1?≤?ai?≤?106)a1,?a2,?...,?an(1?≤?ai?≤?106) — the elements of the list.

输出

Print a single integer: the minimum possible cost to make the list good.

输入样例

4 23 17

1 17 17 16

输出样例

40

Note

In example, number 1 must be deleted (with cost 23) and number 16 must increased by 1 (with cost 17).

A gcd (greatest common divisor) of a set of numbers is the maximum integer that divides all integers in the set. Read more about gcd here.

思路

以上是关于A1-2017级算法上机第一次练习赛 P ModricWang's Number Theory II的主要内容,如果未能解决你的问题,请参考以下文章

A1-2017级算法上机第一次练习赛 L Bamboo的OS实验

A1-2017级算法上机第一次练习赛 B ModricWang和数论

A1-2017级算法上机第一次练习赛 D 水水的Horner Rule

A1-2017级算法上机第一次练习赛 I jhljx学位运算

A1-2017级算法上机第一次练习赛 G 股票交易

A1-2017级算法上机第一次练习赛 H 模式寻对