Here you can find the source of lcm(int a, int b)
Parameter | Description |
---|---|
a | an integer value. |
b | an integer value. |
public static int lcm(int a, int b)
//package com.java2s; /*/* w ww . j a v a2s. c o m*/ * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Returns the lowest common multiple between a and b. * * @param a * an integer value. * @param b * an integer value. * @return the lowest common multiple between a and b. */ public static int lcm(int a, int b) { return b * a / gcd(a, b); } /** * Returns the greatest common divisor between a and b. * * @param a * an integer value. * @param b * an integer value. * @return the greatest common divisor between a and b. */ public static int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } }