-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCD.java
More file actions
39 lines (39 loc) · 929 Bytes
/
GCD.java
File metadata and controls
39 lines (39 loc) · 929 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
39
import java.util.*;
//Greatest common divisor
class solution
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int n = 0; n < t; n++)
{
int a = sc.nextInt();
int b = sc.nextInt();
int m;
if(a>b)
{
m = a;
}
else
{
m = b;
}
int ma = 0;
for(int i = m; i > 1; i--)
{
if ((a%i == 0) & (b%i == 0))
{
ma += 1;
System.out.println("GCD of '"+a+"' and '"+b+"' is : "+i);
break;
}
}
if (ma == 0)
{
System.out.println("There is no GCD of "+a+" and "+b+".");
}
}
sc.close();
}
}