Last active
December 9, 2019 21:09
-
-
Save liketheflower/e7bc2188dddc69083b4719195ccd63b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import math | |
import os | |
import random | |
import re | |
import sys | |
# | |
# Complete the 'getTotalX' function below. | |
# | |
# The function is expected to return an INTEGER. | |
# The function accepts following parameters: | |
# 1. INTEGER_ARRAY a | |
# 2. INTEGER_ARRAY b | |
# | |
def getTotalX(a, b): | |
# Write your code here | |
gcd = b[0] | |
for i in range(1, len(b)): | |
gcd = math.gcd(gcd, b[i]) | |
lcm = a[0] | |
for i in range(1, len(a)): | |
lcm = (lcm*a[i])//(math.gcd(lcm, a[i])) | |
if gcd %lcm ==0: | |
return len([i*lcm for i in range(1, gcd//lcm+1) | |
if gcd%(i*lcm)==0]) | |
return 0 | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment