BOJ_2193_이친수_java

2022. 12. 22. 11:51Algorithm/BOJ

728x90

BOJ_2193_이친수

코드

/**
 백준 2103번 이친수
 실버 3
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class BOJ_2193_이친수 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        long ans = solution(N);
        System.out.println(ans);
    }
    private static long solution(int N){
        if (N == 0) return 0;
        else if(N == 1) return 1;
        else if(N == 2) return 1;

        long before = 1;
        long after = 2;
        long fibo = 2;
        for(int i = 3; i <N; i++){
            fibo = before + after;
            before = after;
            after = fibo;
        }

        return fibo;
    }
}

'Algorithm > BOJ' 카테고리의 다른 글

BOJ_12852_1로 만들기 2_java  (0) 2023.01.10
BOJ_14938_서강그라운드_java  (0) 2023.01.09
BOJ_13172_Σ_java  (0) 2023.01.06
BOJ_2448_별 찍기 11_java  (0) 2022.12.28
BOJ_1406_에디터_java  (0) 2022.12.27