-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
25 lines (21 loc) · 855 Bytes
/
Main.java
File metadata and controls
25 lines (21 loc) · 855 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int test_case = Integer.parseInt(br.readLine());
for (int tc = 0; tc < test_case; tc++) {
String[] numbers = br.readLine().split(" ");
int distance = Integer.parseInt(numbers[1]) - Integer.parseInt(numbers[0]);
int n = (int) Math.sqrt(distance);
if (distance == n * n) {
System.out.println(n * 2 - 1);
} else if (n * n < distance && distance <= n * n + n) {
System.out.println(n * 2);
} else {
System.out.println(n * 2 + 1);
}
}
}
}