File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
2022/Contests/Div 2/766/Programs Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+ #include < algorithm>
4
+ #include < map>
5
+
6
+ using namespace std ;
7
+
8
+ int main ()
9
+ {
10
+ int no_of_elements;
11
+ cin >> no_of_elements;
12
+
13
+ vector <int > A (no_of_elements + 1 );
14
+ for (int i = 1 ; i <= no_of_elements; i++)
15
+ {
16
+ cin >> A[i];
17
+ }
18
+
19
+ const int MAX_N = 1e6 + 5 ;
20
+ vector <int > is_present (MAX_N, false );
21
+ for (int i = 1 ; i <= no_of_elements; i++)
22
+ {
23
+ is_present[A[i]] = true ;
24
+ }
25
+
26
+ vector <int > multiple_gcd (MAX_N, 0 );
27
+ for (int i = 1 ; i < MAX_N; i++)
28
+ {
29
+ for (int multiple = i; multiple < MAX_N; multiple += i)
30
+ {
31
+ if (is_present[multiple])
32
+ {
33
+ multiple_gcd[i] = __gcd (multiple_gcd[i], multiple);
34
+ }
35
+ }
36
+ }
37
+
38
+ int new_elements = 0 ;
39
+ for (int i = 1 ; i < MAX_N; i++)
40
+ {
41
+ if (!is_present[i] && multiple_gcd[i] == i)
42
+ {
43
+ new_elements++;
44
+ }
45
+ }
46
+
47
+ cout << new_elements << " \n " ;
48
+ return 0 ;
49
+ }
50
+
51
+
52
+
You can’t perform that action at this time.
0 commit comments