Codeforces Round #766 (Div. 2) - D. Not Adding
GCD + 调和级数
题意
有 \(n\;(1<=n<=10^6)\) 个互不相同的数 \(a[i]\;(1<=a[i]<=10^6)\), 每次可以在 a 数组中选择两个数 \(a[i],a[j]\), 将令 \(d=gcd(a[i],a[j])\), 如果 \(d\), 不在 a 数组中,就把 \(d\) 加进去
求最多能加进去多少个数
思路
- 看到值域只有 \(10^6\), 可以想到可能与调和级数有关
- 对于数论题,很多时候可以更换枚举的顺序,所以可以枚举 \(d\), 看 \(d\) 能不能被加进去
- 对于所有 \(d\) 的倍数,如果他们的 \(gcd\) 等于 \(d\), 说明 \(d\), 可以被加进去
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
#define endl "\n"
typedef long long ll;
typedef pair<int, int> PII;
const int N = 1e6 + 10;
int n;
int cnt[N];
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
int ans = 0;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
cnt[x]++;
}
for (int d = 1; d <= N - 10; d++)
{
int g = 0;
for (int i = d; i <= N - 10; i += d)
if (cnt[i]) g = __gcd(g, i);
if (g == d && !cnt[d]) ans++;
}
cout << ans << endl;
return 0;
}
Codeforces Round #766 (Div. 2) - D. Not Adding的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
随机推荐
- oracle通过计划任务备份表
1.先手动创建表 create table user01_backup_20210204 select * from user01 commit; 2.清空表 truncate table user0 ...
- linux top 指令各列含义
Linux 的 top 指令用于显示机器上正在运行的进程的信息.下面是 top 指令各列的含义: PID:进程 ID,用于标识进程. USER:进程所有者的用户名. PR:进程优先级. NI:进程的& ...
- HttpClient线程池&重试机制
HttpClientUtils package com.example.http_thread.util; import org.apache.http.HttpEntityEnclosingRequ ...
- 对Frobenius 范数的理解
Frobenius 范数是一种矩阵范数,记为 ∣ ∣ ⋅ ∣ ∣ F ||·||_F ∣∣⋅∣∣F,定义为一个矩阵所有元素平方和的开方,即 ∣ ∣ X ∣ ∣ F = ∑ i ∑ j x i , j ...
- QT debug/moc_frmalarminfo.o:(.data.rel.ro._ZTV12FrmAlarmInfo[_ZTV12FrmAlarmInfo]+0x1c0): undefined reference to `non-virtual thunk to FrmAlarmInfo::~FrmAlarmInfo()'解决方法
这个报错很具有迷惑性,,,我在网上还看见了ZTI12的报错,但是仔细一看发现是.o文件报错. 简单解释下.o文件(此解释来自百度): o 就是object, 也就相当于windows下编译的obj文件 ...
- MobilePBRLighting优化思路2
在最近的研究工作中,进一步对移动端PBRLighting进行了优化,以下是一些优化截图,由于后续整理文章使用: PBRLighting(未开启伽马矫正): MobilePBRLighting(高质量版 ...
- unity 阿拉伯数字转中文汉字
直接调用即可 代码如下: using System; using System.Collections; using System.Collections.Generic; using System. ...
- 【安全记录】certutil实战使用总结
前言 在先知看到一篇关于certutil命令的文章(关于certutil的探究),讲得很详细.很全面.特此记录下本人在渗透时使用certutil的一些方法. 在cmd下使用certutil下载远程文件 ...
- Java集合-Set接口
Set接口-介绍 Set接口的定义如下: Set是一个继承于Collection的接口,即Set也是集合中的一种.Set是没有重复元素的集合.即: Set 接口:无序,不支持索引,不可重复的集合 Se ...
- JWT 工具类的编写
导入JWT pom依赖 <!--JWT 依赖--><dependency> <groupId>io.jsonwebtoken</groupId> < ...