Codeforces Round #511 Div.1 A Div.2 C
嗯切一题走人很开心。
gzy-50分比我还惨。
题意:有n个数,去掉尽量少的数使得剩下数的gcd变大。
首先把这n个数都除以gcd,就变成了去掉尽量少的数使得gcd不等于1。
可以枚举一个质数,然后统计这个质数是a数组中多少个数的约数。
线性筛,记录每个数最小的约数,每次除以约数,\(O(n\log a)\)。
Time Limit Exceeded on pretest 8
线性筛的时候顺便记录每个数去掉重复约数之后的数
\(2*3*5*7*11*13*17*19\),再乘23就炸了
每个数最多8个不同质因数
所以就是\(O(8n)\)的了
#include<bits/stdc++.h>
#define il inline
#define vd void
#define ll long long
il int gi(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
int pr[1000000],a[15000001],yes[15000001];
int d[15000001],dd[15000001];
int ans[1000000];
main(){
int n=gi(),g=0;
for(int i=1;i<=n;++i)a[i]=gi(),g=std::__gcd(g,a[i]);
for(int i=1;i<=n;++i)a[i]/=g;
for(int i=2;i<=15000000;++i){
if(!yes[i])pr[++pr[0]]=i,d[i]=pr[0],dd[i]=i;
for(int j=1;j<=pr[0]&&1ll*i*pr[j]<=15000000;++j){
yes[i*pr[j]]=1;
d[i*pr[j]]=j;dd[i*pr[j]]=dd[i]*pr[j];
if(i%pr[j]==0){dd[i*pr[j]]=dd[i];break;}
}
}
dd[1]=1;
int Ans=0;
for(int i=1;i<=n;++i){
a[i]=dd[a[i]];
while(a[i]!=1)++ans[d[a[i]]],a[i]/=pr[d[a[i]]];
}
for(int i=1;i<=pr[0];++i)Ans=std::max(Ans,ans[i]);
Ans=n-Ans;
if(Ans==n)Ans=-1;
printf("%d\n",Ans);
return 0;
}
Codeforces Round #511 Div.1 A Div.2 C的更多相关文章
- Codeforces Round #511 (Div. 2)
Codeforces Round #511 (Div. 2) #include <bits/stdc++.h> using namespace std; int n; int main() ...
- Codeforces Round #539Ȟȟȡ (Div. 1) 简要题解
Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解
Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...
- Codeforces Round #511 (Div. 2):C. Enlarge GCD(数学)
C. Enlarge GCD 题目链接:https://codeforces.com/contest/1047/problem/C 题意: 给出n个数,然后你可以移除一些数.现在要求你移除最少的数,让 ...
- Codeforces Round #511 (Div. 2)-C - Enlarge GCD (素数筛)
传送门:http://codeforces.com/contest/1047/problem/C 题意: 给定n个数,问最少要去掉几个数,使得剩下的数gcd 大于原来n个数的gcd值. 思路: 自己一 ...
- Codeforces Round #511 (Div. 1) C. Region Separation(dp + 数论)
题意 一棵 \(n\) 个点的树,每个点有权值 \(a_i\) .你想砍树. 你可以砍任意次,每次你选择一些边断开,需要满足砍完后每个连通块的权值和是相等的.求有多少种砍树方案. \(n \le 10 ...
- 2018.9.21 Codeforces Round #511(Div.2)
只写了AB,甚至还WA了一次A题,暴露了蒟蒻的本质=.= 感觉考的时候有好多正确或和正解有关的思路,但是就想不出具体的解法或者想的不够深(长)(怕不是过于鶸) 话说CF的E题怎么都这么清奇=.= A. ...
- C. Enlarge GCD Codeforces Round #511 (Div. 2)【数学】
题目: Mr. F has nn positive integers, a1,a2,…,an. He thinks the greatest common divisor of these integ ...
- B. Cover Points Codeforces Round #511 (Div. 2)【数学】
题目: There are nn points on the plane, (x1,y1),(x2,y2),…,(xn,yn)(x1,y1),(x2,y2),…,(xn,yn). You need t ...
随机推荐
- 铁乐学python_day28_模块学习3
大部份内容摘自授课老师的博客http://www.cnblogs.com/Eva-J/ OS模块复习一二 >>> import os >>> os.getcwd() ...
- MySQL 索引的介绍与应用
Mysql索引 一. mysql 索引 索引是对数据库表中一列或多列的值进行排序的一种结构,使用索引可快速访问数据库表中的特定信息. 二:MySQL索引类型 按存储结构区分:聚集索引(又称聚类索引,簇 ...
- 缓冲区溢出基础实践(一)——shellcode 与 ret2libc
最近结合软件安全课程上学习的理论知识和网络资料,对缓冲区溢出漏洞的简单原理和利用技巧进行了一定的了解.这里主要记录笔者通过简单的示例程序实现缓冲区溢出漏洞利用的步骤,按由简至繁的顺序,依次描述简单的 ...
- 使用redis4.0.1和redis-cluster搭建集群并编写重启shell脚本
1.删除机器上原有的redis2.8 关闭redis-server killall -9 redis-server 查找redis文件所在目录 which redis 删除相关文件 rm -rf re ...
- Hadoop学习之路(十六)Hadoop命令hadoop fs -ls详解
http://blog.csdn.net/strongyoung88/article/details/68952248
- webpack.config.js配置遇到Error: Cannot find module '@babel/core'问题
在webpack配置,将ES6转成ES5的时候,,出现Error: Cannot find module '@babel/core'错误最初以为是babel-core没有安装上.重装了好几遍babel ...
- servlet使用
一.使用IDEAL创建项目 1) 2) 3) 4) 5) 6) 7) 8) 9) 二.路径介绍: 配置文件: servlet配置文件: package ser_Test; import javax.s ...
- JDBC 使用common-dbutiles
一:第三方jar mysql-connector-java-5.1.45-bin.jar,需要关注的核心类: 1.DbUtils----操作数据库的连接注册和释放. 2:.QueryRunner--- ...
- JDK(九)JDK1.7源码分析【集合】HashMap的死循环
前言 在JDK1.7&1.8源码对比分析[集合]HashMap中我们遗留了一个问题:为什么HashMap在调用resize() 方法时会出现死循环?这篇文章就通过JDK1.7的源码来分析并解释 ...
- Ajax的async属性
Ajax请求中的async:false/true的作用 官方的解释是:http://api.jquery.com/jQuery.ajax/ async Boolean Default: true By ...