forked from amankayat/HackerRank-Solution-Algorithm-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbetween2sets.cpp
More file actions
49 lines (44 loc) · 925 Bytes
/
between2sets.cpp
File metadata and controls
49 lines (44 loc) · 925 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
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
int btwsets(int a[100],int b[100],int n,int m){
int count=0,k=0,p,c[100];
int last=a[n-1];
while(last<=b[0]){
for(int i=0;i<n;i++){
if(last%a[i]==0)
p=1;
else{
p=0;
break;
}
}
if(p==1){
c[k]=last;
k++;
}
last++;
}
for(int i=0;i<k;i++){
for(int j=0;j<m;j++){
if(b[j]%c[i]==0)
p=1;
else{
p=0;
break;
}
}
if(p==1)
count++;
}
return count;
}
int main(){
int n,m,a[100],b[100];
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<m;i++)
cin>>b[i];
int result = btwsets(a,b,n,m);
cout<<result;
}