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.
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int NumPrime;
int Prime[*];
bool isPrime[*]={,};
ll num[*],sum[*];
void init(){
for(int i=;i<=*;i++){
if(!isPrime[i]){
Prime[NumPrime++]=i;
}
for(int j=;j<NumPrime&&i*Prime[j]<*;j++){
isPrime[i*Prime[j]]=;
if(i%Prime[j]==) break;
}
}
}
int Max=-;
int main(){
init();
int cnt;
int n,x,y;
scanf("%d%d%d",&n,&x,&y);
for(int i=;i<=n;i++){
scanf("%d",&cnt);
num[cnt]++;
sum[cnt]+=cnt;
Max=max(Max,cnt);
}
for(int i=;i<=Max*;i++){
num[i]+=num[i-];
sum[i]+=sum[i-];
}
int lim=x/y;
ll ans=1e18;
for(int i=;i<NumPrime&&Prime[i-]<=Max;i++){
ll cot=;
for(int j=;j*Prime[i]<=Max;j++){
ll lit=max((j+)*Prime[i]-lim-,j*Prime[i]);
// cout<<lit<<endl;
cot+=(num[lit]-num[j*Prime[i]])*x;
ll a=sum[(j+)*Prime[i]]-sum[lit];
ll b=num[(j+)*Prime[i]]-num[lit];
// cout<<num[(j+1)*Prime[i]]<<"A "<<<<endl;
cot+=(b*((j+)*Prime[i])-a)*y;
// cout<<cot<<"B"<<endl;
//if(cot>ans) break;
}
// cout<<cot<<endl;
ans=min(ans,cot);
}
printf("%lld\n",ans);
return ;
}
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 分区间操作 #include <cstdio> #include <cstdlib> # ...
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)ABCD
A. Arpa and a research in Mexican wave time limit per test 1 second memory limit per test 256 megaby ...
- Codeforces Round #432 (Div. 1, based on IndiaHacks Final Round 2017) D. Tournament Construction(dp + 构造)
题意 一个竞赛图的度数集合是由该竞赛图中每个点的出度所构成的集合. 现给定一个 \(m\) 个元素的集合,第 \(i\) 个元素是 \(a_i\) .(此处集合已经去重) 判断其是否是一个竞赛图的度数 ...
- 【前缀和】【枚举倍数】 Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D. Arpa and a list of numbers
题意:给你n个数,一次操作可以选一个数delete,代价为x:或者选一个数+1,代价y.你可以进行这两种操作任意次,让你在最小的代价下,使得所有数的GCD不为1(如果全删光也视作合法). 我们从1到m ...
- 【推导】【暴力】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) C. Five Dimensional Points
题意:给你五维空间内n个点,问你有多少个点不是坏点. 坏点定义:如果对于某个点A,存在点B,C,使得角BAC为锐角,那么A是坏点. 结论:如果n维空间内已经存在2*n+1个点,那么再往里面添加任意多个 ...
- 【推导】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) B. Arpa and an exam about geometry
题意:给你平面上3个不同的点A,B,C,问你能否通过找到一个旋转中心,使得平面绕该点旋转任意角度后,A到原先B的位置,B到原先C的位置. 只要A,B,C构成等腰三角形,且B为上顶点.那么其外接圆圆心即 ...
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) C
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two poi ...
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) B
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points a, ...
- 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. Th ...
随机推荐
- Centos 6.3 编译安装Nginx+php+Mysql
1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables 将 -A INPUT -m state --state NEW -m tcp -p tcp --dpo ...
- 分享知识-快乐自己:SpringMVC 结合使用拦截器(判断是否用户是否已登陆)
基础拦截器操作: 拦截器是一种AOP操作实现,那么在AOP之中用户一定不需要去关注拦截器的存在,用户只需要按照自己已经习惯的处理方式进行代码的编写即可. 首先我们先创建一个自定义的拦截器: packa ...
- 分布式锁的实现方式——ACID数据库、缓存或者是zk
针对分布式锁的实现,目前比较常用的有以下几种方案: 基于数据库实现分布式锁 基于缓存(redis,memcached,tair)实现分布式锁 基于Zookeeper实现分布式锁 在分析这几种实现方案之 ...
- centos7在VMware下配置网络连接
安装成功以后,首先更改vmwar的虚拟网络设置 1.参考连接:http://www.cnblogs.com/liongis/p/3265458.html 2.然后将虚拟机的设置里面将网络配置的连接方式 ...
- VC++动态链接库(DLL)编程深入浅出(转帖:基础班)
1.概论 先来阐述一下DLL(Dynamic Linkable Library)的概念,你可以简单的把DLL看成一种仓库,它提供给你一些可以直接拿来用的变量.函数或类.在仓库的发展史上经历了“无库-静 ...
- BZOJ_2064_分裂_状压DP
BZOJ_2064_分裂_状压DP Description 背景: 和久必分,分久必和... 题目描述: 中国历史上上分分和和次数非常多..通读中国历史的WJMZBMR表示毫无压力. 同时经常搞OI的 ...
- Codeforces 758A. Holiday Of Equality 贪心
题目大意: 给定一个长为\(n\)序列,每次操作在一个数上+1,求最小的操作次数使所有的数大小相同. 题解: 对这种题无话可说 #include <cstdio> #include < ...
- codevs 3049 舞蹈家怀特先生
题目描述 Description 怀特先生是一个大胖子.他很喜欢玩跳舞机(Dance Dance Revolution, DDR),甚至希望有一天人家会脚踏“舞蹈家怀特先生”.可惜现在他的动作根本不能 ...
- 解决mongodb查询慢的问题
最近项目上一直在用mongodb作为数据库,mongodb有他的优势,文档型类json格式存储数据,修改起来比传统的关系型数据库更方便,但是最近在用mongodb出现了查询缓慢的问题,我用命令行查询, ...
- Linux 运维面试问题总结
Linux 运维面试问题总结 1.详细描述mysql主从复制的方式?(类似跟DRBD高可用的协议类型) 答: (1)同步复制(C协议:sync):只有在本地和远程磁盘都确定写入已完成时,主节点才会认为 ...