fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. typedef pair<int, int> ii;
  6.  
  7. const int INF = 1e9;
  8. const ll LINF = 1e18;
  9.  
  10. const int N = 2e5 + 5;
  11. const int MAX_A = 1e6 + 5;
  12.  
  13. int n;
  14. int a[N];
  15.  
  16. int cnt[MAX_A]; // cnt[x] = số phần tử trong mảng a là ước của x
  17.  
  18. int main() {
  19. ios::sync_with_stdio(0); cin.tie(0);
  20. cin >> n;
  21. for (int i = 1; i <= n; i++) cin >> a[i];
  22.  
  23. for (int i = 1; i <= n; i++) cnt[a[i]]++;
  24.  
  25. // Lưu ý thứ tự for để tính mảng cnt[]
  26. for (int i = MAX_A - 1; i >= 1; i--) {
  27. for (int j = 2 * i; j < MAX_A; j += i) cnt[j] += cnt[i];
  28. }
  29.  
  30. int ans = 0;
  31. for (int i = 1; i <= n; i++) {
  32. ans += (cnt[a[i]] - 1 == 0);
  33. }
  34.  
  35. cout << ans << '\n';
  36. }
  37.  
Success #stdin #stdout 0.04s 7924KB
stdin
10
33 18 45 28 8 19 89 86 2 4
stdout
5