辗转相除法
流程图
代码实现
a,b=eval(input())
if a%b==0:
print('最大公约数是:',b)
else:
while a%b!=0:
c=a%b
a=b
b=c
print('最大公约数是:',b)
辗转相减法
流程图
代码实现
a,b=eval(input())
while a!=b:
if a>b:
a=a-b
else:
b=b-a
print('最小公约数是:',b)
穷举法
流程图
代码实现
a,b=eval(input())
temp=a
while temp!=0:
if a%temp==0 and b%temp==0:
print('最大公约数是:',temp)
break
temp-=1
if temp==0:
print('最大公约数是:',a)