You are viewing a single comment's thread. Return to all comments →
Exactly what I thought as well. Nice and short in Python 3 without math.gcd:
import sys def lcm(a): if len(a)==1: return a[0] if len(a)==2: return a[0]*a[1]//gcd((a[0],a[1])) return lcm((a[0],lcm(a[1:]))) def gcd(a): if len(a)==1: return a[0] if len(a)==2: return gcd((a[1],a[0]%a[1])) if a[1]!=0 else a[0] # Euclid's alg return gcd((a[0],gcd(a[1:]))) input() lcm_a = lcm([x for x in map(int,input().strip().split())]) gcd_b = gcd([x for x in map(int,input().strip().split())]) print(sum(1 for x in range(lcm_a,gcd_b+1,lcm_a) if gcd_b%x==0))
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 →
Exactly what I thought as well. Nice and short in Python 3 without math.gcd: