Enlarge GCD(素数筛)
题意
删去最少的数,使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(素数筛)的更多相关文章
- CF 1047 C - Enlarge GCD [素数筛]
传送门:http://codeforces.com/contest/1047/problem/C 题意:给出n个数字,求最少删除几个数可以使剩下的数字的GCD大于n个数字的GCD 思路:最开始想的是先 ...
- BZOJ 2818 GCD 素数筛+欧拉函数+前缀和
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2818 题意:给定整数N,求1<=x,y<=n且Gcd(x,y)为素数的数对( ...
- Codeforces Round #511 (Div. 2)-C - Enlarge GCD (素数筛)
传送门:http://codeforces.com/contest/1047/problem/C 题意: 给定n个数,问最少要去掉几个数,使得剩下的数gcd 大于原来n个数的gcd值. 思路: 自己一 ...
- Codeforces Round #511 (Div. 2):C. Enlarge GCD(数学)
C. Enlarge GCD 题目链接:https://codeforces.com/contest/1047/problem/C 题意: 给出n个数,然后你可以移除一些数.现在要求你移除最少的数,让 ...
- codeforces 414A A. Mashmokh and Numbers(素数筛)
题目链接: A. Mashmokh and Numbers time limit per test 1 second memory limit per test 256 megabytes input ...
- Help Hanzo (素数筛+区间枚举)
Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000). (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...
- 素数筛 poj 2689
素数筛 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ...
- BestCoder Round #85 hdu5778 abs(素数筛+暴力)
abs 题意: 问题描述 给定一个数x,求正整数y,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 输入描述 第一行输入一个整数T 每组数据有一行,一个整 ...
- poj 3048 Max Factor(素数筛)
这题就是先写个素数筛,存到prime里,之后遍历就好,取余,看是否等于0,如果等于0就更新,感觉自己说的不明白,引用下别人的话吧: 素数打表,找出20000之前的所有素数,存入prime数组,对于每个 ...
随机推荐
- 为什么second是秒也是第二?
起源 早期在西方,一小时分为 60 分钟.后来,科学发达了.文明进步了,人们认为一分钟太粗放了.必须划分得更细致,于是就把一分钟划分成 60 等分.由于是对时间的第二次划分,就将新的 60 等分的“单 ...
- sqlserver 返回刚插入的那条数据
insert into xxxxxx(Col_002,UrgentStatus,DoWorkShop,Col_004,Col_005,Col_006,Col_003,Col_007,postQQ,Co ...
- adaptiveThreshold(自适应阈值)
void adaptiveThreshold(InputArray src, OutputArray dst, double maxValue, int adaptiveMethod, int thr ...
- cvpr 2019 workshop&oral session
1. Verification and Certification of Neural Networks神经网络的验证与认证 2. Automated Analysis of Marine Video ...
- android intent调用系统camera
利用android的camera通常有两种方式:利用intent调用系统的camera,或者结合surfaceview实现自己定制的camera.先分别对这两种方法说明如下: 一.使用系统自配的cam ...
- linux命令--truncate 学习
truncate命令可以将一个文件缩小或者扩展到某个给定的大小 可以利用该命令和-s选项来特别指定文件的大小 1.清空一个文件内容,尤其是log 2. truncate -s 0 test
- lnmp源码搭建
Nginx工作原理 这里需要结合Apache的工作,对PHP文件处理过程的区别 1:Nginx是通过php-fpm这个服务来处理php文件 2:Apache是通过libphp5.so ...
- mount -o是什么意思
mount -o是用loop设备, 在 linux挂载本地的(可能是硬盘上的) iso文件时, 使用的. -o 就是loop回环设备的意思. loop回路文件系统: 是: 用来在一个文件系统上实现另一 ...
- [VBA]斐波那契数列
Sub 斐波那契()Dim arrFor i = 3 To 100Cells(1, 1) = 0Cells(2, 1) = 1Cells(i, 1) = Cells(i - 1, 1) + Cells ...
- 是否被封禁ip或端口的检测网站 ping
国内的: http://tool.chinaz.com/port (可以检测端口) https://tools.ipip.net/ping.php (貌似不可以检测端口) 国外的: https://w ...