博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
A1-2017级算法上机第一次练习赛 P ModricWang's Number Theory II
阅读量:5829 次
发布时间:2019-06-18

本文共 1264 字,大约阅读时间需要 4 分钟。

题目描述

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.

思路

转载于:https://www.cnblogs.com/zjsyzmx0527/p/10182676.html

你可能感兴趣的文章
oracle系列(五)高级DBA必知的Oracle的备份与恢复(全录收集)
查看>>
hp 服务器通过串口重定向功能的使用
查看>>
国外10大IT网站和博客网站
查看>>
android第十一期 - SmoothSwitchLibrary仿IOS切换Activity动画效果
查看>>
zabbix 批量web url监控
查看>>
MongoDB CookBook读书笔记之导入导出
查看>>
shell如何快速锁定所有账号
查看>>
HTML 5实现的手机摇一摇
查看>>
Linux 文件IO理解
查看>>
Ninject 2.x细说---2.绑定和作用域
查看>>
30个非常时尚的网页联系表单设计优秀示例
查看>>
使用membership(System.Web.Security)来进行角色与权限管理
查看>>
opticom 语音质量验证白皮书
查看>>
3D实时渲染中的BSP树和多边形剔除
查看>>
Frank Klemm's Dither and Noise Shaping Page: Dither and Noise Shaping In MPC/MP+
查看>>
网络抓包的部署和工具Wireshark【图书节选】
查看>>
Redis在Windows+linux平台下的安装配置
查看>>
Maven入门实战笔记-11节[6]
查看>>
Local declaration of 'content' hides instance variable
查看>>
ASP.NET中 HTML标签总结及使用
查看>>