求两数的最大公约数和最小公倍数

unsigned int gcd(unsigned int a, unsigned int b)
{
  unsigned int rem;
  while (b != 0) {
    rem = a % b;
    a = b;
    b = rem;
  }
  return a;
}

Euclidean辗转相除法

unsigned int lcm(unsigned int a, unsigned int b)
{
  return a / gcd(a, b) * b;
}

根据 greatest common divisor 求 least common multiple

posted on 2013-03-05 17:09  chenkkkabc  阅读(171)  评论(0编辑  收藏  举报