Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D相关的知识,希望对你有一定的参考价值。
?????????gre lin rar cat scanf ack make ... mini
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.
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.
Print a single integer: the minimum possible cost to make the list good.
4 23 17
1 17 17 16
40
10 6 2
100 49 71 73 66 96 8 60 41 63
10
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 }
以上是关于Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) A
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)(示
枚举Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) Div2C题