-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ01022.java
More file actions
41 lines (35 loc) · 953 Bytes
/
Copy pathJ01022.java
File metadata and controls
41 lines (35 loc) · 953 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
40
41
import java.util.*;
import java.math.*;
public class J01022 {
public static long[] s = new long[100];
public static void start() {
s[1] = 1;
s[2] = 1;
for (int i = 3; i < 93; i++) {
s[i] = s[i - 2] + s[i - 1];
}
}
public static int fibo(int n, long k) {
if (n == 1) {
return 0;
} else if (n == 2) {
return 1;
} else {
if (k <= s[n - 2]) {
return fibo(n - 2, k);
} else {
return fibo(n - 1, k - s[n - 2]);
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
start();
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
long k = sc.nextLong();
System.out.println(fibo(n, k));
}
}
}