[백준] 6571번 피보나치 수의 개수

거북이·2023년 3월 27일
0

백준[실버3]

목록 보기
82/92
post-thumbnail

💡문제접근

  • 다이나믹 프로그래밍을 이용한 피보나치 수의 개수를 구하는 문제였다.
  • 주의해야 할 점이 있다면 dp[1] = 1, dp[2] = 2라는 점이다.

💡코드(메모리 : 31256KB, 시간 : 64ms)

import sys
input = sys.stdin.readline

dp = [0] * 1001
dp[1] = 1
dp[2] = 2
for i in range(3, 1001):
    dp[i] = dp[i-1] + dp[i-2]

while True:
    cnt = 0
    a, b = map(int, input().strip().split())
    if a == 0 and b == 0:
        break
    else:
        for i in range(1, 1001):
            if dp[i] >= a and dp[i] <= b:
                cnt += 1
        print(cnt)

💡소요시간 : 18m

0개의 댓글