求最大公約數,展轉相除法。仍然是遞歸和遞推的算法。不解釋,上代碼。python
def divideNum01(n1, n2): while n1 % n2 != 0: r = n1 % n2 n1 = n2 n2 = r else: return n2 def divideNum02(n1, n2): if n1 % n2 == 0: return n2 else: return divideNum02(n2, n1 % n2)