题意:https://www.luogu.com.cn/problem/CF1627D
思路:因为gcd只会越来越小,所以我们可以枚举所以数,看它最后是否会被加入集合。check的方法就是看所以集合中是i倍数的数的gcd是否最终等于i,是的则会。
/*keep on going and never give up*/
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define int long long
typedef pair<int, int> pii;
#define lowbit(x) x&(-x)
#define endl '\n'
#define wk is zqx ta die
int a[1000005];
int vis[1000005];
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
vis[a[i]] = 1;
}
int ans = 0;
for (int i = 1; i <= 1e6; i++) {
if (vis[i]) {
continue;
}
int d = 0;
for (int j = i; j <= 1e6; j += i) {
if (vis[j]) {
d = __gcd(d, j / i);
}
}
if (d == 1) {
ans++;
}
}
cout << ans << endl;
return 0;
}