You are viewing a single comment's thread. Return to all comments →
perhaps easier to understand, but your organization is on point. Uses built-in gcd:
#!/bin/python import sys from fractions import gcd n,m = raw_input().strip().split(' ') n,m = [int(n),int(m)] A = map(int,raw_input().strip().split(' ')) B = map(int,raw_input().strip().split(' ')) def LCM(a, b): return (a*b)//gcd(a,b) lcm = reduce(LCM, A, 1) gcd = reduce(gcd, B) lcm_copy = lcm count = 0 while lcm <= gcd: if(gcd % lcm) == 0: count += 1 lcm = lcm + lcm_copy print(count)
Seems like cookies are disabled on this browser, please enable them to open this website
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
perhaps easier to understand, but your organization is on point. Uses built-in gcd: