题意

删去最少的数,使gcd变大

题解

只要保留相同素数因子最多的数即可。

素数筛。

C++代码

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1.5e7+;
const int MAXM = 1.5e7+;
int Mark[MAXN];
int prime[MAXN]; int Prime(){
int tot = ;
memset(Mark,,sizeof(Mark));
Mark[] = ;
Mark[] = ;
for(int i = ; i < MAXN; i++){
if(Mark[i] == ){
prime[tot++] = i;
} for(int j = ; j < tot && prime[j] * i < MAXN ; j ++)
{
Mark[i * prime[j]] = ;
if(i % prime[j] == )
break;
}
}
return tot ;
} int a[],cnt[MAXN]; int main(){
int n ;
int tot = Prime();
cin >> n;
int g = ;
for(int i = ; i < n ; i++){
cin >> a[i];
g = __gcd(g , a[i]);
}
for(int i = ;i < n ; i++){
a[i] /= g;
for(int j = ; prime[j] * prime[j] <= a[i] ; ++j){
int p = prime[j];
if(a[i] % p == ) cnt[p]++;
while(a[i] % p == ) a[i]/= p;
}
if(a[i]!=) cnt[a[i]] ++;
}
int ans = n;
for(int i = ; i < MAXN; ++i){
ans = min(ans, n - cnt[i]);
}
if(ans == n) ans = -;
cout << ans << endl;
return ;
}

Enlarge GCD(素数筛)的更多相关文章

  1. CF 1047 C - Enlarge GCD [素数筛]

    传送门:http://codeforces.com/contest/1047/problem/C 题意:给出n个数字,求最少删除几个数可以使剩下的数字的GCD大于n个数字的GCD 思路:最开始想的是先 ...

  2. BZOJ 2818 GCD 素数筛+欧拉函数+前缀和

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2818 题意:给定整数N,求1<=x,y<=n且Gcd(x,y)为素数的数对( ...

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

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

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

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

  5. codeforces 414A A. Mashmokh and Numbers(素数筛)

    题目链接: A. Mashmokh and Numbers time limit per test 1 second memory limit per test 256 megabytes input ...

  6. Help Hanzo (素数筛+区间枚举)

    Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000).     (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...

  7. 素数筛 poj 2689

    素数筛 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ...

  8. BestCoder Round #85 hdu5778 abs(素数筛+暴力)

    abs 题意: 问题描述 给定一个数x,求正整数y,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 输入描述 第一行输入一个整数T 每组数据有一行,一个整 ...

  9. poj 3048 Max Factor(素数筛)

    这题就是先写个素数筛,存到prime里,之后遍历就好,取余,看是否等于0,如果等于0就更新,感觉自己说的不明白,引用下别人的话吧: 素数打表,找出20000之前的所有素数,存入prime数组,对于每个 ...

随机推荐

  1. aspose 模板输出

    Dictionary<string, string> dictionnaryBig = new Dictionary<string, string>(); dictionnar ...

  2. Html5大文件断点续传实现方法

    之前仿造uploadify写了一个HTML5版的文件上传插件,没看过的朋友可以点此先看一下~得到了不少朋友的好评,我自己也用在了项目中,不论是用户头像上传,还是各种媒体文件的上传,以及各种个性的业务需 ...

  3. [NOIP2012] 同余方程(第三次考试大整理)

    1265. [NOIP2012] 同余方程 输入文件:mod.in   输出文件:mod.out   简单对比 时间限制:1 s   内存限制:128 MB [题目描述] 求关于 x 的同余方程 ax ...

  4. Shoi2017试题泛做

    一口气做完六个省的省选(误) Day1 [Shoi2017]期末考试 枚举最大的天数,然后代价贪心地O(1)计算. #include <cstdio> #include <algor ...

  5. 洛谷P4208 [JSOI2008]最小生成树计数——题解

    题目传送 前置知识:对于同一个图的所有最小生成树,权值相等的边的数量相同. 可以简单证明一下: 我们可以从kruskal的过程考虑.这个算法把所有边按权值大小从小到大排序,然后按顺序看每条边,只要加上 ...

  6. SpringMVC学习笔记之---RESTful风格

    RESTful风格 (一)什么是RESTful (1)RESTful不是一套标准,只是一套开发方式,构架思想 (2)url更加简洁 (3)有利于不同系统之间的资源共享 (二)概述 RESTful具体来 ...

  7. jenkins 管理员密码重置

    jenkins管理员 admin的密码忘记怎么重置呢? 修改admin的加密密码为123456的加密密码 #jbcrypt:$2a$10$MiIVR0rr/UhQBqT.bBq0QehTiQVqgNp ...

  8. CSS注

    1.css3内容上下左右居中 .box { display:-moz-box; -moz-box-pack:center; -moz-box-align:center; display:-webkit ...

  9. Buffer-Overflow Vulnerability Lab

    实验概述 Buffer overflow 定义  Buffer overflow is defined as the condition in which a program attempts to ...

  10. db2缓冲池调优

    缓存池: 冲池是内存中的一块区域,db2会将用到数据放到缓冲池中提高性能.缓冲池太小,每次查询仍然要到磁盘中操作,达不到缓冲的效果.缓冲池太大,超出操作系统管理的限制,会导致数据库无法连接的错误. 缓 ...