Write a program that computes the least common multiple (LCM) of two integers.
Here are a few examples:
Input will contain multiple lines each with two integers m and n in the range:
0 < m, n < 1 000 000
For each line of input your program should produce a line of output with the LCM of m and n.
Input is given so that the resulting LCM should be less than 1 000 000 000.
12 18
100 60
8 10
36
300
40
lcm
functionYour program should be implemented using a lcm
function
that receives two integers as arguments and returns an integer.
Please refer to the information for the chosen language:
int lcm(int x, int y);
def lcm(x,y):
lcm :: Int -> Int -> Int
with import Prelude hiding (lcm)
int lcm(int x, int y);
public static int LCM(int a, int b)
in a public class Program
public static int lcm(int a, int b)
in a public class LCM
function lcm(a, b)
function lcm (a, b)
def lcm(a, b)
Submit your solution to be graded according to the following list:
lcm
functionCan you reuse your code from the gcd exercise?
try first: gcd
Copyright © 2020-2023 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/lcm