forked from deepanshumishra/JavaAndCPP_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFLOW016.java
More file actions
38 lines (32 loc) · 692 Bytes
/
Copy pathFLOW016.java
File metadata and controls
38 lines (32 loc) · 692 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
34
35
36
37
38
package codechef_lib;
import java.util.Scanner;
public class FLOW016 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i=1;i<=t;i++) {
long a =sc.nextLong();
long b =sc.nextLong();
System.out.println(gcd(a,b)+" "+lcm(a,b));
}
}
public static long lcm(long a,long b) {
for(int i=1;;i++) {
if((a*i)%b==0) {
return a*i;
}else {
continue;
}
}
}
public static long gcd(long a,long b) {
for(long i =Math.min(a, b);;i--) {
if(((a%i)==0)&&((b%i)==0)) {
return i;
}else {
continue;
}
}
}
}