(二)辗转相除法求最大公约数

参考:

// greateast common divisor  ==> gcd
// 辗转相除法 求 最大公约数
// int big = a > b ? a : b;
// int little = a < b ? a : b;
int gcd(int big, int little)
{
    if (big % little == 0){
        return little;
    }
    return gcd(little, big%little);
}

void test()
{
    std::cout << "gcd(4,10)= " << gcd(4, 10) << std::endl;
    std::cout << "gcd(123456, 7890)= " << gcd(123456, 7890) << std::endl;
}

/*
gcd(4,10)= 2
gcd(123456, 7890)= 6
*/
原文地址:https://www.cnblogs.com/walkinginthesun/p/9723564.html