-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQ1_1157.java
More file actions
36 lines (34 loc) · 787 Bytes
/
Q1_1157.java
File metadata and controls
36 lines (34 loc) · 787 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
/*
* Name: Saket Aryan
* Reg No: 2141001066
* PS LINK: https://cses.fi/problemset/task/1157/
*/
import java.util.Scanner;
public class Q1_1157 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long y = sc.nextLong();
long x = sc.nextLong();
y--;
x--;
long m = Math.max(y, x);
long k = 1;
while (k * 4 <= m) {
k *= 4;
}
long c = 0;
while (k > 0) {
long a = y / k;
long b = x / k;
if (a + b == 3) {
c += 3 * k;
} else {
c += Math.abs(a - b) * k;
}
y %= k;
x %= k;
k /= 4;
}
System.out.println(c);
}
}