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为还需要的蜡烛数, ...
随机推荐
- random及循环
题目:使用两种方式求2-20之间偶数的和,分别使用for和while 1.使用for解法: sum=0 for i in range(2,21,2): sum+=i print ("2-20 ...
- 用js实现元素两个元素位置对齐
一.问题描述 使得填表单位那一行字与下面的表格左对齐,对表格使用css中的margin:auto实现了居中,但是对那一行字(用div包裹的)使用margin:auto不生效:并且2021年下面对应的月 ...
- SpringCloudBus实现配置文件动态更新
前言 在SpringCloud之配置中心(config)的使用的基础上加上SpringCloudBus实现配置文件动态更新 在此之前需要修改版本,否则会出现"Endpoint ID 'bus ...
- java中使用 MultipartFile 进行文件上传而且指定了上传的临时路径,但是文件上传成功后,显示临时文件 无法删除为什么
来自 AI BOT 回复:这是因为文件可能正在被应用程序使用,即文件已经被Java程序锁定,使得系统无法对其进行修改或删除.为了解决这个问题,你需要在保存完文件之后把它移动到正确的位置,或者在Java ...
- Linux Conda 使用activate无法进入环境,但list中有环境的路径
安装OpenFace时装了个miniconda,之后就进不去anaconda的其它环境了: (pfld) .....$ conda env list # conda environments: # / ...
- KingbaseES V8R6备份恢复案例之---自定义表空间指定恢复目录数据恢复
案例说明: KingbaseES V8R6在通过sys_rman执行物理备份恢复时,可以通过参数'--kb1-path',指定恢复的数据(data)目录,但如果原备份中包含自定义表空间时,需要建立表空 ...
- idea的操作快捷键
IDEA调试快捷键 F8 跳到下一步 相当于eclipse的F6 F7 进入到方法 相当于eclipse 的F7 F9 恢复程序到下一个断点 相当于eclispe的 进入下一个断点 shift+F8 ...
- 剑指 Offer II 回溯法
086. 分割回文子字符串 用substr枚举 因为是连续的 不是放与不放的问题 class Solution { public: vector<vector<string>> ...
- supervisord and pm2 进程守护工具
目录 安装 pm2 config pm2是一个带有负载均衡功能的应用进程管理器,类似有Supervisor,forever supervisor 特点: 代码修改,实时重启 安装 npm instal ...
- IO学习笔记(全)
IO学习笔记 目录 IO学习笔记 一.IO前置知识--Linux系统 1.1 Linux系统--虚拟文件系统(VFS) 1.1.1 首先我们来了解一下Linux中的文件描述 1.1.2 文件类型 父子 ...