-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewYrCake.java
More file actions
42 lines (40 loc) · 1.17 KB
/
NewYrCake.java
File metadata and controls
42 lines (40 loc) · 1.17 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
import java.util.Scanner;
public class NewYrCake {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
if (sc.hasNextInt()) {
int t = sc.nextInt();
while (t-- > 0) {
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(solve(a, b));
}
}
}
private static int solve(int a, int b) {
long sumEv = 0;
long sumOd = 0;
int lCnt = 0;
long currSize = 1;
while (true) {
long nxtEv = sumEv;
long nxtOd = sumOd;
if (lCnt % 2 == 0) {
nxtEv += currSize;
} else {
nxtOd += currSize;
}
boolean StWhite = (a >= nxtEv && b >= nxtOd);
boolean StDark = (b >= nxtEv && a >= nxtOd);
if (StWhite || StDark) {
sumEv = nxtEv;
sumOd = nxtOd;
lCnt++;
currSize *= 2;
} else {
break;
}
}
return lCnt;
}
}