-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ01022.java
More file actions
36 lines (34 loc) · 801 Bytes
/
J01022.java
File metadata and controls
36 lines (34 loc) · 801 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
package CODE_PTIT;
import java.util.Scanner;
public class J01022 {
static long[] a = new long[93];
public static long fibo(int n, long k){
if(n == 1) return 0;
if(n == 2) return 1;
if(k <= a[n-2]){
return fibo(n-2, k);
}
else {
return fibo(n-1, k - a[n-2]);
}
}
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
int t = inp.nextInt();
a[1] = 1;
a[2] = 1;
for(int i = 3; i <= 92; i++){
a[i] = a[i-1] + a[i-2];
}
while(t-- > 0){
int n = inp.nextInt();
long k = inp.nextLong();
System.out.println(fibo(n,k));
}
}
}
/*
2
6 4
8 19
*/