-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCM.java
More file actions
27 lines (27 loc) · 792 Bytes
/
LCM.java
File metadata and controls
27 lines (27 loc) · 792 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
import java.util.*;
//Least common multiple
class solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
ArrayList<Integer> list = new ArrayList<>();
for (int n = 0; n < t; n++) {
int a = sc.nextInt();
int b = sc.nextInt();
int check = 1;
int count = 1;
while (check > 0)
{
if ((count%a == 0) & (count%b == 0))
{
System.out.println("LCM of '"+a+"' and '"+b+"' is : "+count);
check -= 1;
list.add(count);
}
count += 1;
}
}
System.out.println(list);
sc.close();
}
}