-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay36.java
More file actions
51 lines (51 loc) · 1.05 KB
/
Copy pathDay36.java
File metadata and controls
51 lines (51 loc) · 1.05 KB
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
import java.util.*;
public class Day36{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the no of Test Cases");
int tc = in.nextInt();
for (int i=0;i<tc ;i++ ) {
System.out.println("Enter the First number for Test Case "+(i+1));
int num1 = in.nextInt();
System.out.println("Enter the Second number for Test Case "+(i+1));
int num2 = in.nextInt();
int max = Math.max(num1,num2);
int min = Math.min(num1,num2);
int rem = 0;
int res = 0;
do{
int k=1;
while(min*k<=max){
res = min*k;
k++;
}
rem = max-res;
max = min;
if (rem!=0) {
min = rem;
}
}while(rem!=0);
System.out.println("GCD="+min);
res = 1;
int k=2;
while(num1!=1||num2!=1){
while(num1%k==0&&num2%k==0) {
res*=k;
num1/=k;
num2/=k;
}
while(num1%k==0||num2%k==0){
if (num1%k==0) {
res*=k;
num1/=k;
}else if(num2%k==0){
res*=k;
num2/=k;
}
}
k++;
}
System.out.println("LCM="+res);
}
}
}