Here you can find the source of lcm(int a, int b)
public static int lcm(int a, int b)
//package com.java2s; //License from project: Open Source License public class Main { public static int lcm(int a, int b) { int c = gcd(a, b); if (c == 0) { return 0; }//w w w. j a v a 2s . co m return a / c * b; } public static long lcm(long a, long b) { long c = gcd(a, b); if (c == 0) { return 0; } return a / c * b; } public static int gcd(int a, int b) { if (a > b) { int tmp = a; a = b; b = tmp; } if (a == 0) { return 0; } if (b % a == 0) { return a; } return gcd(b % a, a); } public static long gcd(long a, long b) { if (a > b) { long tmp = a; a = b; b = tmp; } if (a == 0) { return 0; } if (b % a == 0) { return a; } return gcd(b % a, a); } }