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 ...
随机推荐
- Allure 安装及使用
linux下安装方法 Allure requires Java 8 or higher npm install -g allure-commandline --save-dev (如果npm不能 ...
- 《C++ Primer Plus》读书笔记之六—函数探幽
第八章 函数探幽 1.常规函数与内联函数的主要区别不在于编写方式,而在于C++编译器如何将它们组合到程序中. 2.常规函数调用使程序跳到另外一个地址(函数地址),并在函数结束时返回,更详细的的实现过程 ...
- Linux 环境部署记录(三) - Jenkins安装与配置
Jenkins安装 为了兼容生产环境的jdk1.7版本,从官网得知,Jenkins必须是1.6之前的版本,因此下载jenkins-1.596.3-1.1.noarch.rpm到本地进行安装: #移动到 ...
- MapReduce实例2(自定义compare、partition)& shuffle机制
MapReduce实例2(自定义compare.partition)& shuffle机制 实例:统计流量 有一份流量数据,结构是:时间戳.手机号.....上行流量.下行流量,需求是统计每个用 ...
- MySQL复制(一)复制原理探讨
1 复制概述 1.1.复制解决的问题 数据复制技术有以下一些特点: (1) 数据分布 (2) 负载平衡(load balancing) (3) 备份 (4) 高可用性(high availabilit ...
- js面向对象理解
js面向对象理解 ECMAScript 有两种开发模式:1.函数式(过程化),2.面向对象(OOP).面向对象的语言有一个标志,那就是类的概念,而通过类可以创建任意多个具有相同属性和方法的对象.但是, ...
- Objective-C 与命名空间
http://blog.csdn.net/michelle__/article/details/52528172 Objective-C 在Objective-C应用中的所有类名都必须是全局唯一的.命 ...
- shell批量远程连接mysql的方法
一.配置mysql服务器ip列表如下,可自定义: S1 1.1.1.1 3306 user passwd11 dbname_s1S2 2.2.2.2 3306 u ...
- 【转】iOS - SQLite 数据库存储
本文目录 1.SQLite 数据库 2.iOS 自带 SQLite 的使用 3.fmdb 的使用 4.fmdb 多线程操作 5.其他 SQLite 的第三方封装库 回到顶部 1.SQLite 数据库 ...
- Day16 IO流
流的概念和作用 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象.即数据在两设备间的传输称为流,流的本质是数据传输,根据数据传输特性将流抽象为各种类,方便更直观的进行数据操作. Ja ...