GCD(Great Common Digital)

def GCD_brute_force(a,b):
    best = 0
    for d in range(1,min(a,b)+1):
        if (a%d==0 and b%d==0):
            best = d
    return best
def GCD_divide_loop(a,b):
    while b!=0:
        a,b = b,a%b
        print("a:",a)
        print("b:",b)
    return a
# print(GCD_brute_force(4,12))
print(GCD_divide_loop(70,3))

 

posted @ 2024-03-28 12:44  million_yh  阅读(9)  评论(0编辑  收藏  举报