-
Notifications
You must be signed in to change notification settings - Fork 0
/
Between Two Sets.cpp
54 lines (47 loc) · 1.05 KB
/
Between Two Sets.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
#include<iostream>
using namespace std;
int gcd(int a,int b){
if(b==0)
return a;
return gcd(b,a%b);
}
int superlcm(int a[],int n){
int dataStored = a[0];
for(int i=1;i<n;i++){
dataStored = (a[i]*dataStored)/gcd(a[i],dataStored);
}
return dataStored;
}
int supergcd(int a[], int n){
int gcdStored = a[0];
for(int i=1;i<n;i++){
gcdStored = gcd(a[i],gcdStored);
}
return gcdStored;
}
int main(){
int m,n,lcmReturn,gcdReturn;
int arr_a[10],arr_b[10];
int counter=0,flag;
cin>>m>>n;
for(int i=0;i<m;i++)
cin>>arr_a[i];
for(int i=0;i<n;i++)
cin>>arr_b[i];
lcmReturn = superlcm(arr_a,m);
gcdReturn = supergcd(arr_b,n);
for(int i=lcmReturn;i<=gcdReturn;i+=lcmReturn){
flag=0;
for(int j=0;j<n;j++){
if(arr_b[j]%i!=0){
flag=-1;
break;
}
}
if(flag==0)
counter++;
}
cout<<counter;
// cout<<lcmReturn<<endl;
// cout<<gcdReturn;
}