-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ1003.java
More file actions
33 lines (30 loc) · 864 Bytes
/
BOJ1003.java
File metadata and controls
33 lines (30 loc) · 864 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
package ¹éÁØ;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BOJ1003 {
static Integer[][] arr;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
arr = new Integer[41][2];
arr[0][0] = 1;
arr[0][1] = 0;
arr[1][0] = 0;
arr[1][1] = 1;
int N = Integer.parseInt(br.readLine());
while(N-- > 0) {
int n = Integer.parseInt(br.readLine());
fibo(n);
sb.append(arr[n][0] + " " + arr[n][1]).append("\n");
}
System.out.print(sb);
}
static Integer[] fibo(int n) {
if(arr[n][0] == null || arr[n][1] == null) {
arr[n][0] = fibo(n-1)[0] + fibo(n-2)[0];
arr[n][1] = fibo(n-1)[1] + fibo(n-2)[1];
}
return arr[n];
}
}