-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem25.java
51 lines (42 loc) · 1.26 KB
/
Problem25.java
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package dimikOJ;
import java.util.Scanner;
public class Problem25 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int t = input.nextInt();
while (t < 1) {
t = input.nextInt();
}
input.nextLine();
String[] lines = new String[t];
for (int i = 0; i < t; i++) {
String temp = input.nextLine();
String[] tempArray = temp.trim().replaceAll("\\s{2,}", " ").split("\\s");
int a = Integer.parseInt(tempArray[0]);
int b = Integer.parseInt(tempArray[1]);
while (a <= 0 || a > 100000 || b <= 0 || b > 100000) {
temp = input.nextLine();
tempArray = temp.trim().replaceAll("\\s{2,}", " ").split("\\s");
a = Integer.parseInt(tempArray[0]);
b = Integer.parseInt(tempArray[1]);
}
lines[i] = temp.trim().replaceAll("\\s{2,}", " ");
}
input.close();
for (int i = 0; i < t; i++) {
String[] tempArray = lines[i].split("\\s");
int a = Integer.parseInt(tempArray[0]);
int b = Integer.parseInt(tempArray[1]);
System.out.println("LCM = " + lcm(a, b));
}
}
static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
}