abc170D 不能整除其他元素的个数
题面:给定数组A[n],问A中存在多少个下标x,满足A[x]不能整除数组中所有其他元素。
范围:1<=n<=2E5; 1<=A[i]<=1E6
思路:先计数,然后用类似质数筛的方式处理出整除关系,遍历一次统计结果。
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define per(i,a,b) for(int i=b; i>=a; i--)
const int N = 1000000;
int n, cnt[N+1], nok[N+1];
void solve() {
cin >> n;
rep(i,1,n) {
int a;
cin >> a;
cnt[a] += 1;
}
rep(i,1,N) if(cnt[i]) {
for (int j = 2*i; j <= N; j += i) {
nok[j] = 1;
}
}
int ans = 0;
rep(i,1,N) if(cnt[i]==1 && nok[i]==0) {
ans += 1;
}
cout << ans << "\n";
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
while (t--) solve();
return 0;
}