Python求两个正整数的最大公约数和最小公倍数

#-*- encoding: utf-8 -*-

def gcm(a, b):
	assert a > 0 and b > 0,'parameters must be greater than 0.'
	if a >= b:
		if a % b == 0:
			return b
		else:
			return gcm(b, a - b)
	else:
		return gcm(b, a)

def lcm(a, b):
	assert a > 0 and b > 0,'parameters must be greater than 0.'
	return a * b / gcm(a, b)

你可能感兴趣的:(Python求两个正整数的最大公约数和最小公倍数)