原理:辗转相除法
1.迭代求解
int gcd(int a, int b)
{
a>b?a:b;
while (b != 0)
{
int t = a % b;
a = b;
b = t;
}
return a;
}
2.递归求解
int gcd(int a, int b)
{
a>b?a:b;
if (b == 0)
return a;
else
return gcd(b, a % b);
}