您的位置:首页 > 其它

Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D

2017-09-06 10:36 441 查看
Arpa 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.

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

Arpa 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 Arpa to find the minimum possible cost to make the list good.

Input
First line contains three integers n, x and 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) — the elements of the list.

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

Examples

input
4 23 17
1 17 17 16


output
40


input
10 6 2
100 49 71 73 66 96 8 60 41 63


output
10


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.

题意:给出一组数组,删除数字花费x,把数字增加1,花费y,最后使得gcd!=1.求最小花费

解法:实在是...

http://blog.csdn.net/my_sunshine26/article/details/77850352

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int NumPrime;
int Prime[1234567*2];
bool isPrime[1234567*2]={1,1};
ll num[1234567*2],sum[1234567*2];
void init(){
for(int i=2;i<=1234567*2;i++){
if(!isPrime[i]){
Prime[NumPrime++]=i;
}
for(int j=0;j<NumPrime&&i*Prime[j]<1234567*2;j++){
isPrime[i*Prime[j]]=1;
if(i%Prime[j]==0) break;
}
}
}
int Max=-1;
int main(){
init();
int cnt;
int n,x,y;
scanf("%d%d%d",&n,&x,&y);
for(int i=1;i<=n;i++){
scanf("%d",&cnt);
num[cnt]++;
sum[cnt]+=cnt;
Max=max(Max,cnt);
}
for(int i=1;i<=Max*2;i++){
num[i]+=num[i-1];
sum[i]+=sum[i-1];
}
int lim=x/y;
ll ans=1e18;
for(int i=0;i<NumPrime&&Prime[i-1]<=Max;i++){
ll cot=0;
for(int j=0;j*Prime[i]<=Max;j++){
ll lit=max((j+1)*Prime[i]-lim-1,j*Prime[i]);
//  cout<<lit<<endl;
cot+=(num[lit]-num[j*Prime[i]])*x;
ll a=sum[(j+1)*Prime[i]]-sum[lit];
ll b=num[(j+1)*Prime[i]]-num[lit];
//            cout<<num[(j+1)*Prime[i]]<<"A "<<<<endl;
cot+=(b*((j+1)*Prime[i])-a)*y;
// cout<<cot<<"B"<<endl;
//if(cot>ans) break;
}
// cout<<cot<<endl;
ans=min(ans,cot);
}
printf("%lld\n",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐