CSJ2K.j2k.util.MathUtil.lcm C# (CSharp) Метод

lcm() публичный статический Метод

Method that calculates the Least Common Multiple (LCM) of two strictly positive integer numbers.
public static lcm ( int x1, int x2 ) : int
x1 int First number /// ///
x2 int Second number /// ///
Результат int
        public static int lcm(int x1, int x2)
        {
            if (x1 <= 0 || x2 <= 0)
            {
                throw new System.ArgumentException("Cannot compute the least " + "common multiple of two " + "numbers if one, at least," + "is negative.");
            }
            int max, min;
            if (x1 > x2)
            {
                max = x1;
                min = x2;
            }
            else
            {
                max = x2;
                min = x1;
            }
            for (int i = 1; i <= min; i++)
            {
                if ((max * i) % min == 0)
                {
                    return i * max;
                }
            }
            throw new System.InvalidOperationException("Cannot find the least common multiple of numbers " + x1 + " and " + x2);
        }

Same methods

MathUtil::lcm ( int x ) : int