Here you can find the source of LCM(int m, int n)
static private int LCM(int m, int n)
//package com.java2s; public class Main { /**/*from w ww .jav a2 s. co m*/ * @return lcm(|m|, |n|) */ static private int LCM(int m, int n) { if (m < 0) { m = -m; } if (n < 0) { n = -n; } return m * (n / GCD(m, n)); // parentheses important to avoid overflow } /** * @return gcd(|m|, |n|) */ static private int GCD(int m, int n) { if (m < 0) { m = -m; } if (n < 0) { n = -n; } if (0 == n) { return m; } else { return GCD(n, m % n); } } }