python3 求约数

#求一个数的最大约数(不算本身)
def getmaxnum(n):
    num = n //2
    while num >1:
        if n % num ==0:
            print(num)
            break
        else:
            num = num - 1
    else:
        print('sushu')
getmaxnum(455)
#求最大公约数
#greatest common divisor;gcd
def greatest_common_divisor(m,n):
    if m % n ==0:
        return n
    while m%n !=0:
        m,n = n,m%n
    return n
gcd = greatest_common_divisor(25,120)
print(gcd)
#求最小公倍数
#greatest common divisor;gcd
def greatest_common_divisor(m,n):
    if m % n ==0:
        return n
    while m%n !=0:
        m,n = n,m%n
    return n
gcd = greatest_common_divisor(25,120)
print(gcd)
#两数之积 = 最小公倍数 * 最大公约数
#greatest common multiple 缩写为 gcm
def greatest_common_multiple(m,n):
    gcd=greatest_common_divisor(m,n)
    gcm = (m*n)//gcd
    return gcm
gcm = greatest_common_multiple(18,27)
print(gcm)



你可能感兴趣的:(python基础)