-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbetween_two_sets.py
More file actions
53 lines (39 loc) · 1.02 KB
/
between_two_sets.py
File metadata and controls
53 lines (39 loc) · 1.02 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
import math
import os
import random
import re
import sys
def find_lcm(a):
l = a[0]
for i in range(1, len(a)):
l = math.lcm(l, a[i])
return l
def find_gcd(b):
m = b[0]
for i in range(1, len(b)):
m = math.gcd(m, b[i])
return m
def find_multiples(l, m):
counting = 0
multiple = l
while multiple <= m:
if m % multiple == 0:
counting += 1
multiple += l
return counting
def getTotalX(a, b):
# Write your code here
lcm_of_a = find_lcm(a)
gcd_of_b = find_gcd(b)
total_numbers = find_multiples(lcm_of_a, gcd_of_b)
return total_numbers
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[1])
arr = list(map(int, input().rstrip().split()))
brr = list(map(int, input().rstrip().split()))
total = getTotalX(arr, brr)
fptr.write(str(total) + '\n')
fptr.close()