下面欧几里得算法既适用于 a > b,也适用于 a < b,只要 a、b 是正整数。 int gcd(int a, int b) { while (b != 0) { int r = a % b; a = b; b = r; } return a; }