-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbetween two sets.cpp
More file actions
77 lines (72 loc) · 1.27 KB
/
between two sets.cpp
File metadata and controls
77 lines (72 loc) · 1.27 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
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <bits/stdc++.h>
using namespace std;
void getTotalX(int a[],int b[],int n,int m) {
int num,ctr=0,flaga=1,flagb=1;
for(int i=0;i<n;i++)
{ flaga=1;
num=a[i];
for(int j=0;j<n;j++)
{
if(num%a[j]!=0)
{
flaga=0;
break;
}
}
if(flaga==1)
{ flagb=1;
for(int k=0;k<m;k++)
{
if(b[k]%num!=0)
{
flagb=0;
break;
}
}
}
if(flagb==1 && flaga==1)
ctr++;
}
flaga=1;
flagb=1;
for(int i=a[n-1]+1;i<=b[0];i++)
{ flaga=1;
for(int j=0;j<n;j++)
{
if(i%a[j]!=0)
{
flaga=0;
break;
}
}
if(flaga==1)
{ flagb=1;
for(int k=0;k<m;k++)
{
if(b[k]%i!=0)
{
flagb=0;
break;
}
}
}
if(flagb==1 && flaga==1)
ctr++;
}
cout<<ctr;
}
int main() {
int n;
int m;
cin >> n >> m;
int a[n];
for(int a_i = 0; a_i < n; a_i++){
cin >> a[a_i];
}
int b[m];
for(int b_i = 0; b_i < m; b_i++){
cin >> b[b_i];
}
getTotalX(a, b,n,m);
return 0;
}