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.
defgetTotalX(a,b)# Complete this function# 1. find the LCM of all the integers of array A. 最小公倍数lcm1=a.lcm# 2. find the GCD of all the integers of array B. 最大公約数lcd1=b.gcd# 3. Count the number of multiples of LCM that evenly divides the GCD.count=0formin1..100doif(lcd1%(lcm1*m))==0thencount+=1endendputscountendclassArraydeflcmself.inject{|a,b|a.lcm(b)}enddefgcdself.inject{|a,b|a.gcd(b)}endend
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
Ruby version.