首页 > 其他 > 详细

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

时间:2017-09-06 10:45:13      阅读:375      评论:0      收藏:0      [点我收藏+]

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 nx and y (1 ≤ n ≤ 5·1051 ≤ 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).

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

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 int NumPrime;
 5 int Prime[1234567*2];
 6 bool isPrime[1234567*2]={1,1};
 7 ll num[1234567*2],sum[1234567*2];
 8 void init(){
 9     for(int i=2;i<=1234567*2;i++){
10         if(!isPrime[i]){
11             Prime[NumPrime++]=i;
12         }
13         for(int j=0;j<NumPrime&&i*Prime[j]<1234567*2;j++){
14             isPrime[i*Prime[j]]=1;
15             if(i%Prime[j]==0) break;
16         }
17     }
18 }
19 int Max=-1;
20 int main(){
21     init();
22     int cnt;
23     int n,x,y;
24     scanf("%d%d%d",&n,&x,&y);
25     for(int i=1;i<=n;i++){
26         scanf("%d",&cnt);
27         num[cnt]++;
28         sum[cnt]+=cnt;
29         Max=max(Max,cnt);
30     }
31     for(int i=1;i<=Max*2;i++){
32         num[i]+=num[i-1];
33         sum[i]+=sum[i-1];
34     }
35     int lim=x/y;
36     ll ans=1e18;
37     for(int i=0;i<NumPrime&&Prime[i-1]<=Max;i++){
38         ll cot=0;
39         for(int j=0;j*Prime[i]<=Max;j++){
40             ll lit=max((j+1)*Prime[i]-lim-1,j*Prime[i]);
41           //  cout<<lit<<endl;
42             cot+=(num[lit]-num[j*Prime[i]])*x;
43             ll a=sum[(j+1)*Prime[i]]-sum[lit];
44             ll b=num[(j+1)*Prime[i]]-num[lit];
45 //            cout<<num[(j+1)*Prime[i]]<<"A "<<<<endl;
46             cot+=(b*((j+1)*Prime[i])-a)*y;
47            // cout<<cot<<"B"<<endl;
48             //if(cot>ans) break;
49         }
50        // cout<<cot<<endl;
51         ans=min(ans,cot);
52     }
53     printf("%lld\n",ans);
54     return 0;
55 }

 

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

原文:http://www.cnblogs.com/yinghualuowu/p/7483331.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!