본문 바로가기
Python 알고리즘 공부/백준 알고리즘 공부

10870: 피보나치 수 5 (python)

by 두 그루 2023. 1. 7.

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

 

10870번: 피보나치 수 5

피보나치 수는 0과 1로 시작한다. 0번째 피보나치 수는 0이고, 1번째 피보나치 수는 1이다. 그 다음 2번째 부터는 바로 앞 두 피보나치 수의 합이 된다. 이를 식으로 써보면 Fn = Fn-1 + Fn-2 (n ≥ 2)가

www.acmicpc.net

 

# 10870
# 피보나치 수 5
import sys
sys.setrecursionlimit(10 ** 6)

n = int(input())

def get_fibo(num):
    if num == 0:
        return 0
    if num == 1:
        return 1
    return get_fibo(num - 1) + get_fibo(num - 2)

print(get_fibo(n))

https://github.com/soaringwave/Baekjoon-python-algorithm/blob/main/recursion/fibo_with_recursion.py

댓글