嗯切一题走人很开心。

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的更多相关文章

  1. Codeforces Round #511 (Div. 2)

    Codeforces Round #511 (Div. 2) #include <bits/stdc++.h> using namespace std; int n; int main() ...

  2. Codeforces Round #539&#542&#543&#545 (Div. 1) 简要题解

    Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...

  3. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解

    Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...

  4. Codeforces Round #511 (Div. 2):C. Enlarge GCD(数学)

    C. Enlarge GCD 题目链接:https://codeforces.com/contest/1047/problem/C 题意: 给出n个数,然后你可以移除一些数.现在要求你移除最少的数,让 ...

  5. Codeforces Round #511 (Div. 2)-C - Enlarge GCD (素数筛)

    传送门:http://codeforces.com/contest/1047/problem/C 题意: 给定n个数,问最少要去掉几个数,使得剩下的数gcd 大于原来n个数的gcd值. 思路: 自己一 ...

  6. Codeforces Round #511 (Div. 1) C. Region Separation(dp + 数论)

    题意 一棵 \(n\) 个点的树,每个点有权值 \(a_i\) .你想砍树. 你可以砍任意次,每次你选择一些边断开,需要满足砍完后每个连通块的权值和是相等的.求有多少种砍树方案. \(n \le 10 ...

  7. 2018.9.21 Codeforces Round #511(Div.2)

    只写了AB,甚至还WA了一次A题,暴露了蒟蒻的本质=.= 感觉考的时候有好多正确或和正解有关的思路,但是就想不出具体的解法或者想的不够深(长)(怕不是过于鶸) 话说CF的E题怎么都这么清奇=.= A. ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. SCLAlertView-Swift

    SCLAlertView-Swift https://github.com/vikmeup/SCLAlertView-Swift   Animated Alert View written in Sw ...

  2. Django学习---抽屉热搜榜分析【all】

    Python实例---抽屉热搜榜前端代码分析 Python实例---抽屉后台框架分析 Python学习---抽屉框架分析[点赞功能分析] Python学习---抽屉框架分析[数据库设计分析]18031 ...

  3. Python学习---Python的异步IO[all]

    1.1.1. 前期环境准备和基础知识 安装: pip3 install aiohttp pip3 install grequests pip3 install wheel pip3 install s ...

  4. [转载]Matlab中插值函数汇总和使用说明

    http://blog.sciencenet.cn/blog-457143-679275.html MATLAB中的插值函数为interp1,其调用格式为:  yi= interp1(x,y,xi,' ...

  5. Java代理全攻略【有瑕疵:字节码生成部分没看到,最后两节没仔细看,累了】

    Java代理 1.代理模式 定义:给某个对象提供一个代理对象,并由代理对象控制对于原对象的访问,即客户不直接操控原对象,而是通过代理对象间接地操控原对象. 其实就是委托.聚合.中间人. 为了保持行为的 ...

  6. symfony学习笔记2—纯的PHP代码和symfony的区别

    Symfony vs 纯PHP为啥symfony比普通的php文件访问要好?这一章我们写一个简单的php文件项目,然后组织它,你会发现为什么web应用会发展到现在这个样子.最后我们将学习symfony ...

  7. symfony学习笔记1—简介

    1.symfony快速入门还是先看代码结构把,这个是拿到代码的第一印象,app/:整个应用的配置,模版,translations,这个可能是多语言文件什么,src/:项目php文件,vendor/:第 ...

  8. c++作业之圆面积

    代码传送门

  9. bin/hdfs dfs命令

    appendToFile Usage: hdfs dfs -appendToFile <localsrc> ... <dst> 追加一个或者多个文件到hdfs制定文件中.也可以 ...

  10. python第十六课——ascii码

    2.ascii码 美国设计出来的一张编码表,将涉及的字符都编号了,底层仍然还是进行二进制的运算: 记住:3个范围段 1).'0' --> 码值:48 2).'A' --> 码值:65 3) ...