blob: efef982d88690a6a0dcf50ebeb85b918fee8559a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import java.util.Scanner;
public class GcdLcm {
public static int getGCD(int a, int b) {
if (b == 0) {
return a;
}
if (b > a) {
return getGCD(b, a);
} else {
return getGCD(b, a % b);
}
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
System.out.println(getLCM(a, b));
}
public static long getLCM(int a, int b) {
// https://www.idomaths.com/hcflcm.php#formula
return (long) a * (long) b / (long) getGCD(a, b);
}
}
|