package programmers;
public class 피보나치수 {
public static int solution(int n) {
int[] D = new int[n + 1];
D[0] = 0;
D[1] = 1;
for (int i = 2; i <= n; i++) {
D[i] = (D[i - 1] + D[i - 2]) % 1234567;
}
return D[n];
}
public static void main(String[] args) {
System.out.println(solution(3));
System.out.println(solution(5));
}
}
'휴지통 > 알고리즘 & 자료구조' 카테고리의 다른 글
카펫 (0) | 2023.01.02 |
---|---|
다음 큰 숫자 (0) | 2023.01.01 |
숫자의 표현 (0) | 2022.12.30 |
이진 변환 반복하기 (0) | 2022.12.29 |
올바른 괄호 (0) | 2022.12.28 |