// 递归实现
int gcd(int m,int n)
{
if(m < n)
{
int tmp = m;
m = n;
n = tmp;
}
if(n == 0)
return m;
else
return gcd(n,m % n);
}
// 非递归实现
int gcd(int m,int n)
{
if(m < n)
{
int tmp = m;
m = n;
n = tmp;
}
if(n == 0)
return m;
while (n > 0)
{
int tmp = m % n;
m = n;
n = tmp;
}
return m;
}
// 求最大公倍数
int gbs(int m,int n)
{
return m * n / gcd(m,n);
}
转载于:https://www.cnblogs.com/xiaochao2012/archive/2010/07/01/1769220.html