백준 15624번: 피보나치 수 7 #Python

ColorlessDia·2024년 7월 10일

algorithm/baekjoon

목록 보기
234/836
n = int(input())

if n == 0:
    print(0)
elif n < 3:
    print(1)
else:
    before_2 = 1
    before_1 = 1
    current = before_2 + before_1

    for i in range(3, n):
        before_2 = before_1
        before_1 = current
        current = before_2 + before_1

        if 1000000007 <= current:
            current %= 1000000007
    
    print(current)

0개의 댓글