【題解】AtCoder ABC 170D – Not Divisible

【題目敘述】https://atcoder.jp/contests/abc170/tasks/abc170_d

#include <iostream>
using namespace std;

int n, a[1000005], b, ans;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> b;
        a[b]++;
    }
    for (int i = 1; i <= 1000000; i++){
        if (a[i] == 0) continue;
        for (int j = i*2; j <= 1000000; j += i){
            a[j] = 0;
        }
        if (a[i] == 1) ans++;
    }
    cout << ans << "\n";
}

分享本文 Share with friends