zoukankan      html  css  js  c++  java
  • mMathf -》 Unity3d通用脚本

     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 }
  • 相关阅读:
    vim配置
    git rebase
    mongodb的docker-compose.yml
    Nginx配置BrowserRouter跟随react-router
    Flux Architecture & Redux Data Flow & redux & react-redux PPT
    from acwing 从算法数量推算算法复杂度
    evalRPN 逆波兰算术
    二分区间
    Flex布局
    Treap 模板
  • 原文地址:https://www.cnblogs.com/chongxin/p/4161485.html
Copyright © 2011-2022 走看看