Here you can find the source of lcm(int a, int b)
Parameter | Description |
---|---|
a | a parameter |
b | a parameter |
public static int lcm(int a, int b)
//package com.java2s; /*/*from w w w . j ava2 s. c o m*/ * Copyright 2013 National Bank of Belgium * * Licensed under the EUPL, Version 1.1 or ? as soon they will be approved * by the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * * http://ec.europa.eu/idabc/eupl * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. */ public class Main { /** * Computes the least common multiple of two integers. * * @param a * @param b * @return */ public static int lcm(int a, int b) { return a * (b / gcd(a, b)); } /** * Computes the greatest common divisor of two integers. * * @param a * @param b * @return */ public static int gcd(int a, int b) { while (b > 0) { int temp = b; b = a % b; // % is remainder a = temp; } return a; } }