forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabc170_d.cpp
More file actions
38 lines (31 loc) · 661 Bytes
/
abc170_d.cpp
File metadata and controls
38 lines (31 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Problem Code: abc170_d
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
int not_divisible(int N, vector<int>& A) {
int cnt = 0, limit = *max_element(A.begin(), A.end());
vector<bool> mark(limit + 1);
unordered_map<int, int> freq;
for (int x: A)
freq[x]++;
sort(A.begin(), A.end());
for (int i = 0; i < N; i++) {
if (mark[A[i]])
continue;
cnt += freq[A[i]] == 1;
for (int x = A[i]; x <= limit; x += A[i])
mark[x] = true;
}
return cnt;
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
cout << not_divisible(N, A);
return 0;
}