https://www.acmicpc.net/problem/2193



내가 쓴 방법


또 다른 방법


주의사항

90번째 피보나치 수의 크기?

double 써도 안됨


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
package n2193;
 
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        long[] o; // count of one
        long[] z; // count of zero
 
        int n = sc.nextInt();
        o = new long[n+1];
        z = new long[n+1];
 
        long result = 1;
 
        o[1= 1;
        z[1= 0;
        for(int i = 2; i< n+1; i++){
            z[i] = z[i-1+ o[i-1];
            o[i] = z[i-1];
        }
        result = z[n] + o[n];
 
        System.out.println(result);
    }
}
 
cs


+ Recent posts