-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
53 lines (49 loc) · 913 Bytes
/
main.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
#include <iostream>
using namespace std;
#define forn(i,n) for(int i = 0; i < int(n); ++i)
const int maxc = 100;
int gcd(int a, int b) {
while (a && b) {
if (a >= b)
a %= b;
else
b %= a;
}
return a + b;
}
int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
int main() {
int n, m;
cin >> n >> m;
int A = 1, B = 0;
forn (i, n) {
int x;
cin >> x;
A = lcm(A, x);
if (A > maxc) {
cout << 0 << '\n';
return 0;
}
}
forn (i, m) {
int x;
cin >> x;
B = gcd(B, x);
}
if (B % A != 0) {
cout << 0 << '\n';
return 0;
}
B /= A;
int res = 0;
for (int i = 1; i * i <= B; ++i) {
if (B % i == 0) {
++res;
if (i * i != B)
++res;
}
}
cout << res << '\n';
}