Python求最小公倍數

小櫻桃smile發表於2020-12-25
def lcm(x,y):
    if x > y:
        greater = x
    else:
        greater = y
    while True:
        if greater%x==0 and greater%y==0:
            lcm = greater
            break
        else:
            greater += 1
    return lcm
num1 = int(input("請輸入第一個數:"))
num2 = int(input("請輸入第二個數:"))
print(lcm(num1,num2))

相關文章