-
Notifications
You must be signed in to change notification settings - Fork 12
/
BetweenTwoSets.cpp
61 lines (50 loc) · 1.1 KB
/
BetweenTwoSets.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
using namespace std;
bool checkForA(vector<int>& a, int n){
for(int i = 0; i < a.size(); i++){
if(n%a[i] != 0){
return false;
}
}
return true;
}
bool checkForB(vector<int>& b, int n){
for(int i = 0; i < b.size(); i++){
if(b[i]%n != 0){
return false;
}
}
return true;
}
int getTotalX(vector < int > a, vector < int > b){
// Complete this function
int maxi = INT_MIN, n = a.size(), m = b.size();
for(int i = 0; i < m; i++){
maxi = max(b[i], maxi);
}
int lim = sqrt(maxi), ans = 0;
for(int i = 1; i <= maxi; i++){
if(checkForA(a, i)){
if(checkForB(b, i)){
ans++;
}
}
}
return ans;
}
int main() {
int n;
int m;
cin >> n >> m;
vector<int> a(n);
for(int a_i = 0; a_i < n; a_i++){
cin >> a[a_i];
}
vector<int> b(m);
for(int b_i = 0; b_i < m; b_i++){
cin >> b[b_i];
}
int total = getTotalX(a, b);
cout << total << endl;
return 0;
}