题意:n个数的gcd是k,要你删掉最少的数使得删完后的数组的gcd > k

思路:先求出k,然后每个数除以k。然后找出出现次数最多的质因数即可。

代码:

#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include <iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 3e5 + 10;
const int M = 1.5 * 1e7 + 10;
const ull seed = 131;
const int INF = 0x3f3f3f3f;
const int MOD = 1e4 + 7;
int gcd(int a, int b){
return b == 0? a : gcd(b, a % b);
}
int a[maxn];
int p[4000], prime[4000], pn;
int num[M];
void init(){
pn = 0;
memset(p, 0, sizeof(p));
for(int i = 2; i < 4000; i++){
if(!p[i]){
prime[pn++] = i;
}
for(ll j = 0; j < pn && i * prime[j] < 4000; j++){
p[i * prime[j]] = 1;
if(i % prime[j] == 0) continue;
}
}
// printf("%d\n", pn);
}
int main(){
int n, need;
init();
scanf("%d", &n);
memset(num, 0, sizeof(num));
for(int i = 1; i <= n; i++){
scanf("%d", &a[i]);
if(i == 1) need = a[i];
else need = gcd(need, a[i]);
}
for(int i = 1 ; i <= n; i++) a[i] /= need;
int ans = -1;
for(int i = 1; i <= n; i++){
for(int j = 0; j < pn && prime[j] * prime[j] <= a[i]; j++){
if(a[i] % prime[j] == 0){
num[prime[j]]++;
ans = max(ans, num[prime[j]]);
while(a[i] % prime[j] == 0) a[i] /= prime[j];
}
}
if(a[i] > 1){
num[a[i]]++;
ans = max(ans, num[a[i]]);
}
}
if(ans == -1) printf("%d\n", ans);
else printf("%d\n", n - ans);
return 0;
}

CodeForces 1047C Enlarge GCD(数论)题解的更多相关文章

  1. [Codeforces Round511C] Enlarge GCD

    [题目链接] https://codeforces.com/contest/1047/problem/C [算法] 首先求出n个数的最大公约数g , 将每个数除以g , 那么 , 问题就转化为在n个数 ...

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

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

  3. Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论

    Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...

  4. [CodeForces - 1225C]p-binary 【数论】【二进制】

    [CodeForces - 1225C]p-binary [数论][二进制] 标签: 题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory limit 5 ...

  5. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  6. CodeFroces-- 511div2 C. Enlarge GCD

    题目链接:C. Enlarge GCD 给你一个序列 删除一些数看可以让他们之间的gcd变大如果可以输出删除数量最小的个数 先求出共同 gcd 然后除去 找出出现最多的质数 然后减去就可以了 #inc ...

  7. Codeforces Round #410 (Div. 2) 题解 【ABCD】

    A 题意:问你恰好修改一个字符,能不能使得字符串变成回文串 题解:显然直接for一遍,如果长度为偶数,那么不一样的必须是1个:如果长度为奇数,那么不一样的也可以是0个 #include<bits ...

  8. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  9. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

随机推荐

  1. SW3518中文规格书

    SW3518 是一款高集成度的多快充协议双口充电芯片, 支持 A+C 口任意口快充输出, 支持双口独立限流. 其集成了 5A 高效率同步降压变换器, 支持 PPS/PD/QC/AFC/FCP/SCP/ ...

  2. Ice系列--基于IceGrid的部署方案

    前言 前一篇文章介绍了IceGrid的简单应用.这篇文章来介绍一下它的高端玩法-如何将模板,复制组,知名对象应用于部署方案及其作用. 基于模板的部署方案 之前介绍了xml格式的配置文件通过各种描述符如 ...

  3. 微服务网关2-搭建Gateway服务

    一.创建父模块infrastructure 1.创建模块 在guli_parent下创建普通maven模块 Artifact:infrastructure 2.删除src目录 二.创建模块api_ga ...

  4. JVM有哪些垃圾回收器

    JVM 的垃圾回收器 目录 JVM 的垃圾回收器 经典垃圾收集器 Serial 收集器 ParNew 收集器 Parallel Scavenge 收集器 Serial Old 收集器 Parallel ...

  5. apache状态显示报错AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdo...is message

    今天启动apache查看状态发现报错,说不能确认服务器完全确认域名,以下是报错内容: [root@localhost ~]# service httpd status Redirecting to / ...

  6. 在vCenter Server中添加ESXi 主机失败的问题

    报错:出现了常规系统错误: Timed out waiting for vpxa to start 报错是这个,我看了下vcenter的版本是6.5,如图右上,这个报错是因为我ESXI主机是6.7的, ...

  7. 树莓派zero 使用usb串口连接

    使用minicom连接bash$ lsusbBus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hubBus 001 Device 0 ...

  8. [从源码学设计] Flume 之 memory channel

    [从源码学设计] Flume 之 memory channel 目录 [从源码学设计] Flume 之 memory channel 0x00 摘要 0x01 业务范畴 1.1 用途和特点 1.2 C ...

  9. 请不要继续将数据库称为 CP 或 AP - 掘金 https://juejin.im/post/6844903878102614030

    请不要继续将数据库称为 CP 或 AP - 掘金 https://juejin.im/post/6844903878102614030

  10. Spring Cloud 2020.0.1 正式发布!真是头疼。。。

    上一篇:Spring Cloud 2020.0.0 正式发布,全新颠覆性版本! 号外!号外!号外! Spring Cloud 2020.0.0 在去年 12 月底,赶在一年的尾巴最后几天仓促发布了,时 ...