forked from anishLearnsToCode/hackerrank-math
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Restaurant.java
29 lines (24 loc) · 815 Bytes
/
Restaurant.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
// https://www.hackerrank.com/challenges/restaurant
// t: number of test cases
// n: max of l and b in each entry
// T: O(t * log(n))
// S: O(1)
import java.util.Scanner;
public class Restaurant {
private static final Scanner SCANNER = new Scanner(System.in);
public static void main(String[] args) {
int testCases = SCANNER.nextInt();
while (testCases-- > 0) {
final int l = SCANNER.nextInt();
final int b = SCANNER.nextInt();
System.out.println(maximumNumberOfSquares(l, b));
}
}
private static int maximumNumberOfSquares(int l, int b) {
final int sideLength = gcd(l, b);
return (l * b) / (sideLength * sideLength);
}
private static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
}