最大公倍数と最小公倍数(level 1)

950 ワード

1.質問



2.私の回答


def solution(n, m):
    # greatest common divisor
    # least common multiple
    
    common_divisors = []
    for i in range(1, n+1 if n >=m else m+1):
        if n%i== 0 and m%i == 0:
            common_divisors.append(i)
    
    common_multiple = 1
    for j in range(1, n*m+1):
        if j%n == 0 and j%m == 0:
            common_multiple = j
            break
            
    return [max(common_divisors), common_multiple]

3.他人の回答





4.感じ