标签:style blog http io ar color sp on div
1 public class mMathf 2 { 3 /// <summary> 4 /// 辗转 相除法 求 最大公约数 5 /// a / b = k 6 /// a % b = r 7 /// 原理 gcd(a,b) = gcd(b,r) 8 /// 具体 原理 参考 9 /// http://caixinhua1010.blog.163.com/blog/static/10540100920102138139141/ 10 /// </summary> 11 /// <param name="max"></param> 12 /// <param name="min"></param> 13 /// <returns></returns> 14 public static int GCD(int paramter0, int paramter1) 15 { 16 int max = paramter0 > paramter1 ? paramter0 : paramter1; 17 int min = paramter0 <= paramter1 ? paramter0 : paramter1; 18 19 int t, 20 i = max, 21 j = min; 22 while ((max % min) != 0) { 23 t = min; 24 min = max % min; 25 max = t; 26 } 27 return min; 28 } 29 30 /// <summary> 31 /// 求 最小公倍数 32 /// p0 * p1 / gcd(p0,p1) 33 /// </summary> 34 /// <param name="paramter0"></param> 35 /// <param name="paramter1"></param> 36 /// <returns></returns> 37 public static int LCM(int paramter0, int paramter1) 38 { 39 int gcd = GCD(paramter0, paramter1); 40 41 return paramter0 * paramter1 / gcd; 42 } 43 }
标签:style blog http io ar color sp on div
原文地址:http://www.cnblogs.com/chongxin/p/4161485.html