forked from Nehanshj/Algorithmic-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCM.java
More file actions
33 lines (27 loc) · 633 Bytes
/
Copy pathLCM.java
File metadata and controls
33 lines (27 loc) · 633 Bytes
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
30
31
32
33
import java.util.*;
public class LCM {
private static long gcd(long a,long b){
if(b==0){
return a;
}
long x = a%b;
return gcd(b,x);
}
private static long lcm(long a,long b){
return (a/gcd(a,b))*b;
}
/*NAIVE
private static long lcm_naive(int a, int b) {
for (long l = 1; l <= (long) a * b; ++l)
if (l % a == 0 && l % b == 0)
return l;
return (long) a * b;
}
*/
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
long a = scanner.nextLong();
long b = scanner.nextLong();
System.out.println(lcm(a, b));
}
}