最大公因数和最小共倍数

Greated Common Divisor

int GCD(int a, int b)
{
    int temp;
    if(a < b)
    {
        temp = a;
        a = b;
        b = temp;
    }

    if(a % b == 0)
        return b;
    return GCD(b, a % b);
}

Least Common Multiple

//最小公倍数等于两数之积除以最大公约数    
int LCM(int a,int b)
{
   return (a * b) / GCD(a, b); 
}

 

posted @ 2013-11-04 15:49  alexeyqian  阅读(169)  评论(0编辑  收藏  举报