We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Thank you for your solution, you helped me produce this oversized Python 3 code :
#!/bin/python3importsysfromfunctoolsimportreducedeflcm(a:int,b:int)->int:returna*b//gcd(a,b)deflcm_list(lst:list)->int:returnreduce(lcm,lst)defgcd(a:int,b:int)->int:whilea%b!=0:a,b=b,(a%b)returnbdefgcd_list(lst:list)->int:returnreduce(gcd,lst)defevenly_divides(number:int,divisor:int)->bool:return(number%divisor)==0defget_input():n,m=input().strip().split()n,m=[int(n),int(m)]a=[int(a_temp)fora_tempininput().strip().split()]b=[int(b_temp)forb_tempininput().strip().split()]returnn,m,a,bdefmain():n,m,a,b=get_input()# Find LCM of all integers of alcm_value=lcm_list(a)# Find GCD of all integers of bgcd_value=gcd_list(b)# Count the number of multiples of LCM that evenly divides the GCD.counter=0multiple_of_lcm=lcm_valuewhilemultiple_of_lcm<=gcd_value:ifevenly_divides(gcd_value,multiple_of_lcm):counter+=1multiple_of_lcm+=lcm_valueprint(counter)if__name__=="__main__":main()
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
Thank you for your solution, you helped me produce this oversized Python 3 code :