嗯切一题走人很开心。

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. 将CAGradientLayer用作maskView的遮罩图层

    将CAGradientLayer用作maskView的遮罩图层 说明 CAGradientLayer可以用作alpha遮罩,供maskView使用,这两种东西都是非常偏门的东西,但是,偏门不代表功能不 ...

  2. Fix for: Permission denied to access property 'toString'

    Originally posted by rwolffgang here. Hi guys,when developing a game that runs in an iframe (Faceboo ...

  3. Android 4.4中AudioRecord用例 - 录制系统内置声音

    通过API 19新加的MediaRecorder.AudioSource.REMOTE_SUBMIX參数能够让系统App录制系统内置的声音,也就是扬声器的声音.以下是一个巨简单的样例来演示样例怎样通过 ...

  4. BZOJ1022:[SHOI2008]小约翰的游戏John(博弈论)

    Description 小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有n堆石子,小约翰和他的哥哥轮流取石子,每个人取的时候,可以随意选择一堆石子,在这堆石子中取走任意多的石子,但不能一粒石子也不取 ...

  5. P4053 [JSOI2007]建筑抢修

    题目描述 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有N个建筑设施受到了严重的损伤,如果不尽快修复的话,这些建 ...

  6. javascript 中isPrototypeOf 、hasOwnProperty、constructor、prototype等用法

    hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员. isPrototypeOf是用来判断要检查 ...

  7. redis 使用案例

    1.使用redis消息列队发布信息 在一些用户创造用户的应用中(如SNS,微博),可能出现1秒有上千万个用户同时发布消息的情况,此时如果使用mysql可能出现‘too many connections ...

  8. access数据库及其分页的方法

    首先access数据库的话,感觉针对比较小型的网站比较适合.携带方便,不需要按照特定的sql环境. 当然如果使用access数据库的话 1.首先你先要下载办公五合一(access也是其中之一) 2.w ...

  9. virtualbox+vagrant学习-2(command cli)-15-vagrant resume命令

    Resume 格式: vagrant resume [vm-name] 这将恢复先前挂起的vagrant托管计算机,可能与suspend命令一起使用. 默认情况下,配置的预配置程序在运行该命令时将不再 ...

  10. 743. Network Delay Time

    题目来源: https://leetcode.com/problems/network-delay-time/ 自我感觉难度/真实难度: 题意: 分析: 自己的代码: class Solution: ...