嗯切一题走人很开心。

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. 1. 跟踪标记 (Trace Flag) 1117, 1118 文件增长及空间分配方式

    跟踪标记:1117 功能: 默认,同一个文件组下的多个文件,如果某个文件没有可用空间,且设置了自动增长,则该文件自动增长,其他文件大小保持不变: 开启后,同一文件组下的多个文件,如果某个文件没有可用空 ...

  2. UIView使用UIMotionEffect效果

    UIView使用UIMotionEffect效果 这个效果在模拟器上看不了,所以无法截图. UIView+MotionEffect.h  +  UIView+MotionEffect.m // // ...

  3. matlab 函数句柄@的介绍_什么是函数句柄(转)

    http://blog.csdn.net/kevinhg/article/details/8861774 http://www.ilovematlab.cn/thread-30375-1-1.html ...

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

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

  5. 【AT987】高橋君

    题目 成爷爷一眼秒,\(tql!!!\) 多组询问,求 \[\sum_{i=0}^kC_{n}^i \] 发现\(k<=n\)啊,于是我们可以把一组询问抽象成一个区间\([k,n]\) 左指针的 ...

  6. Asp.net MVC 控制器扩展方法实现jsonp

    项目需要,在使用KendoUI,又涉及到jsonp数据格式的处理,网上看到这样一种实现方法,在此小记一下(其实是因为公司里只能上博客园等少数网站,怕自己忘了,好查看一下,哈哈哈) 1. 新建控制器扩展 ...

  7. [luogu1080] 国王游戏

    题面 ​ 这是一个比较经典(害人不浅)的题目啊, 很早就听说过这个题目的大名, 今日得见, 果然非凡题所可以比拟的啊, 行了, 瞎扯就先扯到这里, 题目大意应该是很好解释的, 我就不解释了, 要使得最 ...

  8. 【转】Tomcat 9.0安装配置

    本文转自:http://blog.sina.com.cn/s/blog_15126e2170102w5o8.html 一.JDK的安装与配置 1.从官网下载jdk,注意是jdk不是jre.最好从官网下 ...

  9. 测试html报告 github python3版本

    github源码下载地址:https://github.com/huilansame/HTMLTestRunner_PY3/archive/master.zip 解压后进入文件找到文件:HTMLTes ...

  10. selenium和PhantomJS的安装

    针对w10系统 selenium安装 pip install selenium 默认安装的是3.x版本,但是3.x版本不支持PhantomJS,所以要安装2.x版本 pip install selen ...