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为还需要的蜡烛数, ...
随机推荐
- mybatis面试资料
1.#{}和${}的区别 #{} 数据类型检查: 若检测到字符串类型,就加上引号: 若检测到数值类型,就不加引号. 安全检查: 若变量的值带有引号,会对引号进行转义处理,这样可以防止sql注入. ${ ...
- Software_programming_EnterpriseArch_ServiceWithSingleTonFactory
19:50:31 <UML 模式和应用> P322 系统需要支持多种第三方外部服务,例如费用计算,授权服务,库存系统,都具有不同的API, 而且还无法改变. 解决方案之一: 使用 单例模式 ...
- nginx客户端真实IP配置
https://www.cnblogs.com/kevingrace/p/8269955.html include mime.types; default_type application/octet ...
- PID名词解析
在工程实际中,应用最为广泛的调节器控制规律为比例.积分.微分控制,简称PID控制,又称PID调节. 当被控对象的结构和参数不能完全掌握,或得不到精确的数学模型时,控制理论的 其它技术难以采用时,系统控 ...
- 【c#】csharp_learn
csharp learn JSON C#解析JSON字符串总结 https://www.cnblogs.com/nc923/p/11418583.html c#解析json字符串处理(最清晰易懂的方法 ...
- Ubuntu 添加新用户并制定目录和shell
Ubuntu 添加新用户并制定目录和shell 分类: LINUX 2011-07-07 15:22:54 ubuntu新建的用户并没有新建相应的home目录和对应的shell环境. 下面就总结 ...
- Linux 中设置静态的IP
Topic (What i going to write) Setting the static Ip address in linux Main Information Firstly use CD ...
- 源码编译mariadb
1.写一个一键安装 mariadb 数据库脚本. [root@centos8mini ~]#vim install_mariadb #!/bin/bash#安装包PACKAGE="maria ...
- rxswift自定义扩展UI组件
扩展UI组件时常用到的一些发布者与订阅者如下: 发布者: ControlEvent(专门用于描述 UI 控件所产生的事件) 订阅者(观察者): Binder(专门用于绑定UI状态的,如:当某个状态改变 ...
- uniapp引入腾讯云直播助手插件
在uniapp开发小程序,引入腾讯云直播助手插件 1.在manifest.json文件中,找到微信小程序特有相关,声明要使用的插件 /* 小程序特有相关 */ "mp-weixin" ...