本文共 649 字,大约阅读时间需要 2 分钟。
int GreatestCommonDivisor(int a, int b) { int t; if (a < b) { // 交换两个数,使大数放在a的位置上。 t = a; a = b; b = t; } while (b != 0) { // 利用辗转相除法,直到b为0为止。 t = a % b; a = b; b = t; } return a;} int LeastCommonMultiple(int a, int b) { int t = a * b / GreatestCommonDivisor(a, b); return t;}
转载地址:http://xacr.baihongyu.com/