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

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·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 171 17 17 16

output

40

input

10 6 2100 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

 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 }
时间: 2024-12-29 12:21:29

Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D的相关文章

D. Arpa and a list of numbers Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)

http://codeforces.com/contest/851/problem/D 分区间操作 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9

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

Arpa is researching the Mexican wave. There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0. At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-th spectator

【枚举】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) Div2C题

题目大意: 平面上有N个点(N<=1000),定义一个点为好,当且仅当,由这个点为三角形的顶点,组成的所有三角形,两边的夹角都为钝角,称为好点,求好点的数目. 题目分析: 首先考虑朴素的枚举,枚举三元组<i,j,k>,以i为顶点,j , k 为两边 ,查看是否i为顶点的所有三角形,都以i所在顶点为钝角. 考虑优化: 三角形内角和是180 如果<i, j, k> 是以i为顶点的钝角/直角三角形,则 j, k 是坏点,不需要枚举. 如果<i, j, k> 是锐角,i为

Codeforces Round #500 (Div. 2) [based on EJOI]

Codeforces Round #500 (Div. 2) [based on EJOI] https://codeforces.com/contest/1013 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define IT set<node>::iterator 6 #def

Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E. Buy Low Sell High [贪心 II][数据结构 I]

题目:http://codeforces.com/contest/867/problem/E 题意:模拟股票操作,每天只能买一只股票或者卖一只股票或者什么也不做,求最大利润. 题解:仔细想想是非常简单的一个贪心问题,理解为连续的多次贪心买入卖出可以合并为一次的买入卖出,且值为最优.只需要用一个最小堆每次寻找前面的最小且没有被标记为购买点的值即可.如果自己为最小值,continue.如果那个值没有被选过,为买入点,pop.如果那个值被选为了售出的点,那么取消售出的标记,把当前点标记为售出点,利润直

[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano]

http://codeforces.com/contest/1079/problem/C 题目大意:给出一个数列a[n],让构造一个满足下列条件的数列b[n]:如果a[i]>a[i-1]那么b[i]>b[i-1],如果a[i]<a[i-1]那么b[i]<b[i-1],如果a[i]==a[i-1],那么b[i]!=b[i-1].其中1<=b[i]<=5  1<=a[i]<=2*1e5. 题解:dp[i][j]表示在位置i处取j时是否成立,如果成立则dp[i][

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3

A,有多个线段,求一条最短的线段长度,能过覆盖到所又线段,例如(2,4)和(5,6) 那么我们需要4 5连起来,长度为1,例如(2,10)(3,11),用(3,10) 思路:我们想一下如果题目说的是最长我们肯定是取最小x和最大的y连起来就完事. 但是要求长度最小又得覆盖,那么可以这样想,我们需要把最小的x不断右移到这条线段的y, 最大的左移到x,所以就是最大x-最小y完事 #include <bits/stdc++.h> using namespace std; #define ll long

【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B:数学+排序 C:字符串搜索 A // https://codeforces.com/contest/1277/problem/A /* 题意: 给出一个数,求不大于该数的完美整数的个数(完美整数指全是一个数组成的数字,如:111, 333333, 444444, 9, 8888 ...) 分析:

Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)

题目链接:https://codeforces.com/contest/1315 A - Dead Pixel 诚心诚意的送分题. 题意:给一个n*m的格子矩阵,和一个坏掉的格子,找一个最大的不包含坏掉的格子的矩阵. void test_case() { int n, m, x, y; scanf("%d%d%d%d", &n, &m, &x, &y); int ans = max(x * m, (n - (x + 1)) * m); ans = max