文章目录 计算最大公约数(暴力求解和辗转相除法) 计算最小公倍数 计算最大公约数(暴力求解和辗转相除法) 方法一:暴力求解 def hcf(x,y): smaller = x if x<y else y for ii in range(1,smaller+1): if x%ii==0 and y%ii==0: max_hcf=ii else: pass return max_hcf print(hcf(35,56)) 方法二:辗转相除法 基本逻辑为不断计算两个数的余数