-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathbetween_two_sets.cpp
More file actions
63 lines (57 loc) · 1.19 KB
/
between_two_sets.cpp
File metadata and controls
63 lines (57 loc) · 1.19 KB
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
62
63
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
typedef long long int ll;
int gcd(int a, int b)
{
if (b==0)
return a;
return gcd(b, a%b);
}
int findGCD(vector<int> arr, int n)
{
int result = arr[0];
for (int i=1; i<n; i++)
result = gcd(arr[i], result);
return result;
}
ll findlcm(vector<int> arr, int n)
{
// Initialize result
ll ans = arr[0];
// ans contains LCM of arr[0],..arr[i]
// after i'th iteration,
for (int i=1; i<n; i++)
ans = ( ((arr[i]*ans)) /
(gcd(arr[i], ans)) );
return ans;
}
int getTotalX(vector <int> a, vector <int> b) {
ll lcm=findlcm(a,a.size());
int gcf=findGCD(b,b.size());
int finalCount=0;
for(long i = lcm, j =2; i<=gcf; i=lcm*j,j++)
{
if(gcf%i==0)
{
finalCount++;
}
}
return finalCount;
}
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;
}