Problem:
Fibonacci Number Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula: Input An integer $n$ is given. output Print the $n$-th fibonacci number in a line. Constraints  $0 \leq n \leq 44$  Sample Input 1 3 Sample Output 1 3

Solution (Python):
def memolize(f):
    cache = {}

    def helper(x):
        if x not in cache:
            cache[x] = f(x)
        return cache[x]
    return helper

@memolize
def fib(n):
    if n == 0:
        return 1
    elif n == 1:
        return 1

    return fib(n - 1) + fib(n - 2)

n = int(input())
print(fib(n))

Solution (Python):
def memolize(f):
    cache = {}

    def helper(x):
        if x not in cache:
            cache[x] = f(x)
        return cache[x]
    return helper

@memolize
def fib(n):
    if n == 0:
        return 1
    elif n == 1:
        return 1

    return fib(n - 1) + fib(n - 2)

n = int(input())
print(fib(n))

Solution (Python):
N = int(input())

def memorize(f) :
    cache = {}
    def helper(*args) :
        if args not in cache :
            cache[args] = f(*args)
        return cache[args]
    return helper

@memorize
def fibonacci(n):
    if n == 0 or n == 1:
        return 1
    res = fibonacci(n - 2) + fibonacci(n - 1)
    return res

print(fibonacci(N))

Solution (Python):
N = int(input())

def memorize(f) :
    cache = {}
    def helper(*args) :
        if args not in cache :
            cache[args] = f(*args)
        return cache[args]
    return helper

@memorize
def fibonacci(n):
    if n == 0 or n == 1:
        return 1
    res = fibonacci(n - 2) + fibonacci(n - 1)
    return res

print(fibonacci(N))

Solution (Python):
n = int(input())
f = [1,1]
for i in range(n-1):
    fib = f[-1] + f[-2]
    f.append(fib)
print(f[n])

Solution (Python):
n = int(input().strip())
if n == 0:
    print(1)
elif n == 1:
    print(1)
else:
    lst = [0 for i in range(0,n+1)]
    lst[0] = 1
    lst[1] = 1
    for i in range(0,n-1):
        lst[i+2] = lst[i+1] + lst[i]
    print(lst[n])

Solution (Python):
def fib(n):
    if n ==0 or n == 1:
        return 1
    l = [0] * (n+1)
    l[0] = 1
    l[1] = 1

    for i in range(2,n+1):
        l[i] = l[i-2] + l[i-1]
    return l[i]

print(fib(int(input())))

Solution (Python):
n = int(input())
fib = [0] * (n + 1)
if n == 0 or n == 1:
    print(1)
    exit()
    
fib[0] = 1
fib[1] = 1
for i in range(2, n + 1):
    fib[i] = fib[i - 1] + fib[i -2]

print(fib[-1])

Solution (Python):


import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N=INT()

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

print(dp[N])

Solution (Python):


import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N=INT()

memo=[0]*50
memo[0]=memo[1]=1
def rec(n):
    if memo[n]:
        return memo[n]
    memo[n]=rec(n-1)+rec(n-2)
    return memo[n]

print(rec(N))

Solution (Python):
fib = [0 for i in range(45)]
fib[0] = 1
fib[1] = 1
for i in range(2, 45):
  fib[i] = fib[i - 1] + fib[i - 2]
n = int(input())
print(fib[n])

Solution (Python):
cache = {}
def fib(x):
	if x in cache:
		return cache[x]
	elif x == 0 or x == 1:
		return 1
	else:
		v = fib(x - 1) + fib(x - 2)
		cache[x] = v
		return v

x = input()
print fib(x)

Solution (Python):
def memoize(f):  
    cache = {}  
    def helper(x):  
        if x not in cache:              
            cache[x] = f(x)  
        return cache[x]  
    return helper 
         
@memoize
def fib(n):
    if n in (0, 1):
        return 1
    else:
        return fib(n - 1) + fib(n - 2)
 
print(fib(int(input())))

Solution (Python):
def fib(n):
    def iter(a, b, cnt):
        if cnt == 0:
            return a
        return iter(b, a+b, cnt-1)
    return iter(1, 1, n)

if __name__ == '__main__':
    n = int(input())
    print(fib(n))

Solution (Python):
def Fibonacci(n, a1, a2):
	if n<1 : return a1
	return Fibonacci(n-1,a1+a2,a1)

print( Fibonacci( int(input()), 1, 0 ) )

Solution (Python):
def fib(n):
    global f
    if f[n]==False:
        val=fib(n-1)+fib(n-2)
        f[n]=val
        return val
    else:
        return f[n]


n=int(input())
N=44+1
f=[1,1]
f.extend([0]*N)
fib(N)
print(f[n])

Solution (Python):



n = int(input()) - 1
fib = [1, 2]
for i in range(2, n + 1):
    fib.append(fib[i - 1] + fib[i - 2])
print(fib[n])

Solution (Python):
n = int(raw_input())
dp = {}

def fib(n):
    if n in dp: return dp[n]
    if n == 0:
        dp[n] = 1
        return 1
    elif n == 1:
        dp[n] = 1
        return 1
    else:
        dp[n] = fib(n-1)+fib(n-2)
        return dp[n]

print fib(n)

Solution (Python):
n = input()

if n == 0:
    print(1)
elif n == 1:
    print(1)
else:
    fib = [0 for i in range(n + 1)]

    fib[0] = 1
    fib[1] = 1

    for i in range(2, n + 1):
        fib[i] = fib[i - 1] + fib[i - 2]

    print(fib[n])

Solution (Python):




import sys
io = sys.stdin

n = io.readline()

a0, a1 = [1, 1]
a2 = 1
for i in xrange(int(n)-1):
    a2 = a0 + a1
    a0, a1 = a1, a2

print a2

Solution (Python):
def fib(n):
  if F[n] != 0:
    return F[n]
  elif n==0 or n==1:
    F[n] = 1
  else:
    F[n] = fib(n-1) + fib(n-2)

  return F[n]



n = input()
F = [0 for row in range(n+1)]
print fib(n)

Solution (Python):
def fib_iter(n):
  fib_n  = 1
  fib_n2 = 1
  fib_n1 = 1
  for i in range(n - 1):
    fib_n  = fib_n1 + fib_n2
    fib_n2 = fib_n1
    fib_n1 = fib_n
  return fib_n

x = int(raw_input())

print fib_iter(x)

Solution (Python):
memo = {}

def fib_memo(n):
  if n <= 1:
    return 1
  if n in memo:
    return memo[n]
  memo[n] = fib_memo(n - 1) + fib_memo(n - 2)
  return memo[n]

x = int(raw_input())

print fib_memo(x)

Solution (Python):
n = int(input())


def memoize(f):
    memo = [1, 1] + [0] * max(0, n - 1)

    def main(i):
        if memo[i]:
            return memo[i]
        result = memo[i] = f(i)
        return result

    return main


@memoize
def fibonacci(i):
    return fibonacci(i - 1) + fibonacci(i - 2)


print(fibonacci(n))

Solution (Python):
n = int(raw_input())
F = [0] * (n+1)



def fibonacci(n):
    global F
    if n == 0 or n == 1:
        F[n] = 1
        return F[n]
    if F[n] != 0:
        return F[n]
    F[n] = fibonacci(n-2) + fibonacci(n-1)
    return F[n]

def makeFibonacci(n):
    global F
    F[0] = 1
    F[1] = 1
    for i in xrange(2,n+1):
        F[i] = makeFibonacci(i-2) + makeFibonacci(i-1)
    return F[n]

def main():
    ans = fibonacci(n)
    print ans
    return 0

main()

Solution (Python):
class Fib():
    f = [1] * 50
    def fib(self, n):
        for i in range(2, n + 1):
            self.f[i] = self.f[i - 1] + self.f[i - 2]
        return(self.f[n])

x = Fib()
print(x.fib(int(input())))

Solution (Python):

fibo_list=[0 for i in range(48)]

def fibo(n):
    f=fibo_list[n]
    if f:
        return f
    else:
        if n==0 or n==1:
            return 1
        else:
            f=fibo(n-1)+(fibo(n-2))
    fibo_list[n]=f
    return f


n=input()
print(fibo(n))

Solution (Python):
def fib(n):
    n1 = n2 = tmp = 1
    for _ in range(n - 1):
        tmp = n1 + n2
        n1, n2 = n2, tmp
    return tmp

print(fib(int(input())))

Solution (Python):
a,b = 1,1
n = int(input())
for i in range(n):
	a,b = b,a+b


print(a)

Solution (Python):
def fibo(n):
	S=[1,1]
	s=1
	if n>1:
		for i in range(2,n+1):
			S.append(S[i-1]+S[i-2])
			s=S[i]
	return s

def main():
	if __name__=="__main__":
		n=input()
		print(fibo(n))

main()

Solution (Python):
def fibo(n):
	S=[1,1]
	s=1
	if n>1:
		for i in range(2,n+1):
			S.append(S[i-1]+S[i-2])
			s=S[i]
	return s

def main():
	if __name__=="__main__":
		n=int(input())
		print(fibo(n))

main()

Solution (Python):
def fib2(n):
    a1, a2 = 1, 0
    while n > 0:
        a1, a2 = a1 + a2, a1
        n -= 1
    return a1


n = int(input())

print(fib2(n))

Solution (Python):
answer_list = [1, 1] + [None] * 43

def fib(num):
    ans = answer_list[num]
    if ans:
        return ans
    ans = fib(num - 1) + fib(num - 2)
    answer_list[num] = ans
    return ans


n = int(input())

print(fib(n))

Solution (Python):
def deco_fibo(func):
    answer_list = [1, 1] + [None] * 43
    def main_fibo(i):
        ans = answer_list[i]
        if ans:
            return ans
        ans = func(i)
        answer_list[i] = ans
        return ans
    return main_fibo

@deco_fibo
def fibo(num):
    return fibo(num - 1) + fibo(num - 2)


n = int(input())

print(fibo(n))

Solution (Python):


fib = [1, 1]
for i in range(2, 45):
    fib.append(fib[i-1]+fib[i-2])

n = int(raw_input())
print fib[n]

Solution (Python):
def fibonum():
    global F
    F[0]=1
    F[1]=1
    for i in xrange(2,n+1):
        F[i]=F[i-1]+F[i-2]
    return F[n]

n=input()
F=[0]*(n+1)
num=fibonum()
print(num)

Solution (Python):
def fib(n):
    if ft[n] != 0:
        return ft[n]
    else:
        ft[n] = fib(n - 1) + fib(n - 2)
        return ft[n]

ft = [0] * 45
ft[0] = ft[1] = 1
print fib(int(input()))

Solution (Python):
def fib(n, fib_memo=None):                                                                                                                                                    
    if fib_memo == None:                                                                                                                                                      
        fib_memo = [None]*n                                                                                                                                                   
    if n <= 1:                                                                                                                                                                
        return 1                                                                                                                                                              
    else:                                                                                                                                                                     
        if fib_memo[n-1] == None:                                                                                                                                             
            fib_memo[n-1] = fib(n-1, fib_memo)                                                                                                                                
        if fib_memo[n-2] == None:                                                                                                                                             
            fib_memo[n-2] = fib(n-2, fib_memo)                                                                                                                                
        return fib_memo[n-1] + fib_memo[n-2]                                                                                                                                  
                                                                                                                                                                              
                                                                                                                                                                              
if __name__ == '__main__':                                                                                                                                                    
    n = input()                                                                                                                                                               
    print(fib(int(n)))

Solution (Python):


def fibo(n, numbers):
    if n == 0 or n == 1:
        numbers[n] = 1
        return numbers[n]
    elif numbers[n]:
        return numbers[n]
    else:
        numbers[n] = fibo(n - 1, numbers) + fibo(n - 2, numbers)
        return numbers[n]

n = int(input())
fibonacci_numbers = [0 for i in range(n + 1)]
print(fibo(n, fibonacci_numbers))

Solution (Python):
F =[1,1] + [0 for i in range(44)]

n = int(input())

for i in range(2,n+1):
  F[i]=F[i-1]+F[i-2]

print(F[n])

Solution (Python):
def fib(n):
    F = {0:1, 1:1}
    def fibonacci(n):
        ans = F.get(n,-1)
        if ans > 0: return ans
        F[n] = fibonacci(n-1) + fibonacci(n-2)
        return F[n]
    return fibonacci(n)
        
if __name__=='__main__':
    print(fib(int(input())))

Solution (Python):
if __name__ == "__main__":
    n = input()
    F = []
    F.append(1)
    F.append(1)
    for i in range(2,n+1):
        F.append(F[i-1] + F[i-2])

    print(F[n])

Solution (Python):


memo = ['' for i in xrange(45)]


def recursion(n):
    if n == 0 or n == 1:
        return 1

    return recursion(n - 1) + recursion(n - 2)


def memo_search(n):
    if memo[n] != '':
        return memo[n]
    else:
        if n == 0 or n == 1:
            memo[n] = 1
            return 1
        memo[n] = memo_search(n - 1) + memo_search(n - 2)
        return memo[n]

if __name__ == '__main__':
    n = input()
    
    print memo_search(n)

Solution (Python):


memo = ['' for i in xrange(45)]
dp = [0 for i in xrange(45)]



def recursion(n):
    if n == 0 or n == 1:
        return 1

    return recursion(n - 1) + recursion(n - 2)



def memo_search(n):
    if memo[n] != '':
        return memo[n]
    else:
        if n == 0 or n == 1:
            memo[n] = 1
            return 1
        memo[n] = memo_search(n - 1) + memo_search(n - 2)
        return memo[n]



def dynamic_programming(n):
    for i in xrange(n + 1):
        if i == 0 or i == 1:
            dp[i] = 1
        else:
            dp[i] = dp[i - 1] + dp[i - 2]
    return dp[n]


if __name__ == '__main__':
    n = input()
    
    
    print dynamic_programming(n)

Solution (Python):
n = int(input())

fib = [1]*2 + [0]*(n-1)

for i in range(2, n+1):
    fib[i] = fib[i-1] + fib[i-2]


print(fib[n])

Solution (Python):
def fib(memo,n):
    if n in memo:
        return memo[n]
    else:
        if n == 0:
            return 1
        elif n == 1:
            return 1
        else:
            memo[n] = fib(memo,n-1)+fib(memo,n-2)
            return memo[n]

memo = {}
n = int(raw_input())
print fib(memo,n)

Solution (Python):
def fib(n):
    if n == 0:
        return 1
    if n == 1:
        return 1
    if F[n] > 0:
        return F[n]
    F[n] = fib(n-1) + fib(n-2)
    return F[n]

n = int(input())
F = [0 for i in range(n+1)]
print(fib(n))

Solution (Python):
fib = [1 for i in range(45)]
for i in range(2, 45):
    fib[i] = fib[i - 1] + fib[i - 2]
i = int(input())
print(fib[i])

Solution (Python):
def fib(n):
    if n == 0 or n == 1:
        return 1
    if A[n] is not None:
        return A[n]
    A[n] = fib(n - 1) + fib(n - 2)
    return A[n]


A = [None] * (44 + 1)
n = int(input())
print(fib(n))

Solution (Python):


n = int(input()) + 1
arr = [-1] * n

arr[0] = 1
arr[1] = 1

for i in range(2, len(arr)):
    arr[i] = arr[i - 1] + arr[i - 2]

print(arr[n - 1])

Solution (Python):
n=input()

fn_first=1
fn_second=1

if n >= 2:
    for x in xrange(n-1):
        tmp = fn_first
        fn_first = fn_first + fn_second
        fn_second = tmp

print fn_first

Solution (Python):


def fibonacciDP(i):
    if i == 0:
        return 1
    elif i == 1:
        return 1
    else:
        if dp[i-1] is None and dp[i-2] is None:
            dp[i-1] = fibonacciDP(i-1)
            dp[i-2] = fibonacciDP(i-2)
        elif dp[i-1] is None:
            dp[i-1] = fibonacciDP(i-1)
        elif dp[i-2] is None:
            dp[i-2] = fibonacciDP(i-2)

        return dp[i-1]+ dp[i-2]

def fibonacci(i):
    if i == 0:
        return 1
    elif i == 1:
        return 1
    else:
        return fibonacci(i-1)+fibonacci(i-2)



n = int(input())
dp = [None]*n

print(fibonacciDP(n))

Solution (Python):

def FN(n):
    if n==0 or n==1:
        F[n]=1
        return F[n]
    if F[n]!=None:
        return F[n]
    F[n]=FN(n-1)+FN(n-2)
    return F[n]

if __name__=="__main__":
    n=int(input())
    F=[None]*(n+1)
    ans=FN(n)
    print(ans)

Solution (Python):



import sys


def fib_bad(n):
    if not n or n == 1:
        return 1
    return fib_bad(n - 2) + fib_bad(n - 1)


def fib_dp(n):
    fib_list[:1] = [1, 1]
    for i in range(2, n + 1):
        fib_list[i] = fib_list[i - 2] + fib_list[i - 1]
    return fib_list.pop()


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    index = int(_input[0])
    fib_list = [None] * index
    
    print(fib_dp(index))

Solution (Python):



import sys








def fib_dp(n):
    fib_list[:1] = [1, 1]
    for i in range(2, n + 1):
        fib_list[i] = fib_list[i - 2] + fib_list[i - 1]
    return fib_list.pop()


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    index = int(_input[0])
    fib_list = [None] * index
    print(fib_dp(index))

Solution (Python):



import sys








def fib_dp(n):
    fib_list[:1] = [1, 1]
    for i in range(2, n + 1):
        fib_list[i] = fib_list[i - 2] + fib_list[i - 1]
    return fib_list[n]


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    index = int(_input[0])
    fib_list = [None] * index
    print(fib_dp(index))

Solution (Python):
class Fibonacci(object):
    memo = [1, 1]

    def get_nth(self, n):
        if n < len(Fibonacci.memo):
            return Fibonacci.memo[n]
        
        for i in range(len(Fibonacci.memo), n+1):
            result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
            Fibonacci.memo.append(result)
            
        return Fibonacci.memo[n]


if __name__ == '__main__':
    
    num = int(input())

    
    f = Fibonacci()
    result = f.get_nth(num)

    
    print('{0}'.format(result))

Solution (Python):
from functools import lru_cache


@lru_cache(maxsize=None)
def fib(n):
    if n < 2:
        return n
    return fib(n-1) + fib(n-2)


class Fibonacci(object):
    memo = [1, 1]

    def get_nth(self, n):
        if n < len(Fibonacci.memo):
            return Fibonacci.memo[n]
        
        for i in range(len(Fibonacci.memo), n+1):
            result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
            Fibonacci.memo.append(result)
            
        return Fibonacci.memo[n]


if __name__ == '__main__':
    
    num = int(input())

    
    
    
    result = fib(num+1)

    
    print('{0}'.format(result))

Solution (Python):
from functools import lru_cache


@lru_cache(maxsize=None)
def fib(n):
    """ http://docs.python.jp/3/library/functools.html """
    if n < 2:
        return n
    return fib(n-1) + fib(n-2)


class Fibonacci(object):
    memo = [1, 1]

    def get_nth(self, n):
        if n < len(Fibonacci.memo):
            return Fibonacci.memo[n]
        
        for i in range(len(Fibonacci.memo), n+1):
            result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
            Fibonacci.memo.append(result)
            
        return Fibonacci.memo[n]


if __name__ == '__main__':
    
    num = int(input())

    
    f = Fibonacci()
    result = f.get_nth(num)
    

    
    print('{0}'.format(result))

Solution (Python):
from functools import lru_cache


@lru_cache(maxsize=None)
def fib(n):
    """ http://docs.python.jp/3/library/functools.html """
    if n < 2:
        return n
    return fib(n-1) + fib(n-2)


class Fibonacci(object):
    memo = [1, 1]

    def get_nth(self, n):
        if n < len(Fibonacci.memo):
            return Fibonacci.memo[n]
        
        for i in range(len(Fibonacci.memo), n+1):
            result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
            Fibonacci.memo.append(result)
            
        return Fibonacci.memo[n]


if __name__ == '__main__':
    
    num = int(input())

    
    
    
    result = fib(num+1)

    
    print('{0}'.format(result))

Solution (Python):
def fibonacci(n):
    num1 = 1
    num2 = 1
    tmp = 1

    for i in range(1, n):
        tmp = num1 + num2
        num1 = num2
        num2 = tmp

    return tmp


if __name__ == '__main__':
    n = int(input())
    result = fibonacci(n)
    print(result)

Solution (Python):




def fibonacci(n):
    num1 = 1
    num2 = 1
    tmp = 1

    for i in range(1, n):
        tmp = num1 + num2
        num1 = num2
        num2 = tmp

    return tmp


if __name__ == '__main__':
    n = int(input())
    result = fibonacci(n)
    print(result)

Solution (Python):
n = int(input())
memo = [1, 1] + [0 for _ in range(n-1)]
for i in range(n+1):
    if not memo[i]:
        memo[i] = memo[i - 1] + memo[i - 2]
print(memo[-1])

Solution (Python):
a=b=1
for _ in range(int(input())):a,b=b,a+b
print(a)

Solution (Python):
from functools import lru_cache

@lru_cache(maxsize=None)
def fib(n):
    if n <= 1:
        return 1
    else:
        return fib(n - 1) + fib(n - 2)

n = int(input())
ans = fib(n)

print(ans)

Solution (Python):
def fib(n):
    f0, f1 = 1, 1

    for i in range(n - 1):
        f1, f0 = f1 + f0, f1

    return f1

n = int(input())
ans = fib(n)

print(ans)

Solution (Python):
n = int(input())

first = 1
second = 1
for i in range(n-1):
    second, first = first + second, second
print(second)

Solution (Python):
F = [1,1]
for i in range(2, int(input())+1):
    F.append(F[i-2] + F[i-1])
print(F[-1])

Solution (Python):
a = [1]*45
for i in range(2,len(a)):
  a[i] = a[i-1] + a[i-2]
  
print(a[int(input())])

Solution (Python):
n = int(input())

fib = [1]*(n+1)

for i in range(2,n+1):
    fib[i] = fib[i-1]+fib[i-2]
    
print(fib[n])

Solution (Python):
def fib(n):
    if n == 0 or n == 1:
        ans[n] = 1
        return 1
    
    if ans[n] != -1:
        return ans[n]

    ans[n] = fib(n-1) + fib(n-2)
    return ans[n]


N = int(input())
ans = [-1 for i in range(N+1)]
a = fib(N)
print(a)

Solution (Python):
n = int(input())
F = [1, 1]
for i in range(2,n+1):
    F.append(F[i-1] + F[i-2])
print(F[n])

Solution (Python):
def fibonacci(n, memo=None):
    if memo==None:
        memo = [None]*n
    if n<=1:
        return 1 
    else:
        if memo[n-2]==None:
            memo[n-2] = fibonacci(n-2, memo)
        if memo[n-1]==None:
            memo[n-1] = fibonacci(n-1, memo)
    return memo[n-1] + memo[n-2]

n = int(input())
print(fibonacci(n))

Solution (Python):

 
 
def main(n):
    lst = [1, 1]
    for i in range(2, n + 1):
        lst.append(lst[i - 2] + lst[i - 1])
    return lst[n]
 

if __name__ == '__main__': 
    n = int(input())
    print(main(n))

Solution (Python):



def main(n):
    lst = [1, 1]
    for i in range(2, n + 1):
        lst.append(lst[i - 1] + lst[i - 2])
    return lst[n]


if __name__ == '__main__':
    n = int(input())
    print(main(n))

Solution (Python):


def main():
    def _fibonacci(n,cache):
        if n in cache:
            return cache[n]

        elif n == 0 or n == 1:
            ret = 1
            cache[n] = ret
            return ret
        else:
            ret = _fibonacci(n - 1, cache) + _fibonacci(n - 2, cache)
            cache[n] = ret
            return ret

    N = int(raw_input())
    cache = {}
    return _fibonacci(N,cache)

print main()

Solution (Python):
def fib(n, fib_table):
    if n == 0 or n == 1:
        return 1
    if fib_table[n] != None:
        return fib_table[n]
    fib_table[n] = fib(n-1, fib_table) + fib(n-2, fib_table)
    return fib_table[n]

n = int(input())
fib_table = [None]*(n+1)
fib_table[0] = 1
fib_table[1] = 1

print(fib(n, fib_table))

Solution (Python):


def main():
    n = int(input())
    dp = [0] * 100
    dp[0] = 1
    dp[1] = 1
    for i in range(2, len(dp)):
        dp[i] = dp[i - 1] + dp[i - 2]
    print(dp[n])


if __name__ == '__main__':
    main()

Solution (Python):
def fibonacci(n):
    if n == 0 or n == 1:
        F[n] = 1
        return F[n]
    if F[n] is not None:
        return F[n]
    F[n] = fibonacci(n - 1) + fibonacci(n - 2)
    return F[n]


n = int(input())
F = [None]*(n + 1)
print(fibonacci(n))

Solution (Python):
a, b = 1, 1
for i in range(int(input())):
  a, b = b, a + b
print(a)

Solution (Python):
_fib = [None] * 45
_fib[0] = 1
_fib[1] = 1

def fib(n):
    if _fib[n] is None:
        _fib[n] = fib(n-1) + fib(n-2)
    return _fib[n]

_n = int(raw_input())
print(fib(_n))

Solution (Python):
def makeFibonacci(n):
    if n <= 1:
        return str(1)
    F = [None]*(n+1)
    F[0] = 1
    F[1] = 1
    for i in range(2, n+1):
        F[i] = F[i-1] + F[i - 2]
    return str(F[n])

n = int(input())
print(makeFibonacci(n))

Solution (Python):
N = 44
F = [0]*(N+1)

def dynamic(n):
    if n == 0 or n == 1:
        return 1
    if F[n] != 0:
        return F[n]
    F[n] = dynamic(n - 1) + dynamic(n - 2)
    return F[n]

if __name__ == '__main__':
    n = int(raw_input())
    print(dynamic(n))

Solution (Python):
F = {}

def fib(n):
  global F
  if n < 0:
    print("error")
    exit()
  if n < 2:
    F[n] = 1
    return F[n]

  F[n] = F[n-1] + F[n-2]
  return F[n]

n = int(input())




for i in range(n+1):
  result = fib(i)
print(result)

Solution (Python):
F = {}

def fib(n):
  global F
  if n < 0:
    print("error")
    exit()
  if n < 2:
    F[n] = 1
    return F[n]
  F[n] = F[n-1] + F[n-2]
  return F[n]

n = int(input())
for i in range(n+1):
  result = fib(i)
print(result)

Solution (Python):


n = int(input())

def fib(n):
    l = list()
    l.append(1)
    l.append(1)

    for i in range(2, n+1):
        l.append(l[i-1] + l[i-2])

    return l[-1]

print(fib(n))

Solution (Python):
n = int(input())

memo = [0 for _ in range(45)]

def fib_memo(n):
    if memo[n] != 0:
        return memo[n]
    elif (n == 0) or (n == 1):
        return 1
    else:
        memo[n] = fib_memo(n-1) + fib_memo(n-2)
        return memo[n]
    
print(fib_memo(n))

Solution (Python):
n = int(input())

dp = [0 for _ in range(45)]

def fib_dp(n):
    dp[0] = 1
    dp[1] = 1
    for i in range(2, n+1):
        dp[i] = dp[i-1] + dp[i-2]
    return dp[n]
       
print(fib_dp(n))

Solution (Python):
def f(n):
    a, b=1, 1
    for i in range(n):
        a, b=a+b, a
    return b
print(f(int(input())))

Solution (Python):
def g(a,b,n):
    if n==0 or n==1: return a
    else: return g(a+b,a,n-1)
a,b=1,1
print(g(a,b,int(input())))

Solution (Python):
def g(a,b,n):
    if n==0 or n==1: return a
    else: return g(a+b,a,n-1)
a,b=1,1
print(g(a,b,int(input())))

Solution (Python):
def g(a,b,n):
    if n==1:return a
    else:return g(a+b,a,n-1)
a,b=1,1
print(g(a,b,int(input())))

Solution (Python):
def g(a,b,n):
    if n==1:return a
    else:return g(a+b,a,n-1)
print(g(1,1,int(input())))

Solution (Python):



import sys
import re
import math
import itertools
import functools
import logging

logging.basicConfig(level=logging.DEBUG, format="DBG: %(message)s")

def dbg(msg, *args, **kwargs):
    logging.debug(msg, *args, **kwargs)

def fib(n):
    assert n >= 0

    f0 = 1
    f1 = 1

    if n == 0: return f0
    if n == 1: return f1

    for _ in range(n-1):
        f2 = f1 + f0
        f0 = f1
        f1 = f2

    return f2

def main():
    n = int(input())

    print(fib(n))

if __name__ == "__main__": main()

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    F = [1, 1]
    for i in range(n-1):
        F.append(F[-2]+F[-1])
    print(F[n])

Solution (Python):
print([1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170][int(input())])

Solution (Python):
print([1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170][int(input())])

Solution (Python):
n = int(input().strip())
if n <= 1:
    print(1)
    raise SystemExit
prev1 = 1
prev2 = 1
for i in range(2, n+1):
    fib = prev2 + prev1
    prev2, prev1 = prev1, fib
print(fib)

Solution (Python):
n = int(input().strip())
if n <= 1:
    print(1)
    raise SystemExit
prev1 = 1
prev2 = 1
for i in range(2, n+1):
    fib = prev2 + prev1
    prev2, prev1 = prev1, fib
print(fib)

Solution (Python):


def fib(n):
    global fib_list
    if fib_list[n]:
        return fib_list[n]

    if n == 0:
        fib_list[0] = 1
        return 1
    elif n == 1:
        fib_list[1] = 1
        return 1
    else:
        fib_list[n] = fib(n-2) + fib(n-1)
        return fib(n-2) + fib(n-1)

n = int(input())
fib_list = [None for i in range(n+1)]
print(fib(n))

Solution (Python):
def main():
    n = input()
    F = [0]*(n+1)
    number = fibonacci(n,F)
    print number

def fibonacci(n,F):
    if n == 0 or n == 1:
        F[n] = 1
        return 1
    if F[n] != 0:
        return F[n]
    else:
        F[n] = fibonacci(n-2,F)+fibonacci(n-1,F)
        return F[n]

if __name__ == "__main__":
    main()

Solution (Python):
n = int(raw_input())
a = 1
b = 1
for i in range(n-1):
    tmp = a
    a = b
    b += tmp
print b

Solution (Python):
memo = {}

def fib(n):
    key = n
    
    if key in memo:
        return memo[key]
    
    if n == 0:
        return 1
    if n == 1:
        return 1
    if n > 1:
        memo[key] = fib(n-1) + fib(n-2)
    
    return memo[key]

n = int(input())
print(fib(n))

Solution (Python):

import sys
sys.setrecursionlimit(100000)

calculated = set([0, 1])
cal_fib = [0 for _ in range(45)]
cal_fib[0:2] = 1, 1

def fib(n):
    if cal_fib[n] == 0:
        cal_fib[n] = fib(n-1) + fib(n-2)
    return cal_fib[n]

n = int(input())
print(fib(n))

Solution (Python):
def main():
    """ ????????? """
    num = int(input().strip())
    F = []
    for n in range(num+1):
        if n < 2:
            F.append(1)
        else:
            F.append(F[n-1] + F[n-2])
    print (F[num])
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())

cache = {0: 1, 1: 1}
def fibonacci(n):
    if cache.get(n, None) is not None:
        return cache[n]
    cache[n] = fibonacci(n-1) + fibonacci(n-2)
    return cache[n]

print(fibonacci(n))

Solution (Python):
def fibonacci(n):
    a, b = 1, 1
    for i in range(n-1):
        a, b = b, a+b

    return b

if __name__ == '__main__':
    n = int(input())
    print(fibonacci(n))

Solution (Python):


import sys, math, os


PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


n = int(input())
if n < 2:
    print(1)
else:
    a, b = 1, 1
    for k in range(n - 1):
        a, b = b, a + b
    print(b)

Solution (Python):
target = int(input()) + 1
fib = [0 for n in range(target + 1)]
for i in range(target + 1):
    if i == 0:
        continue
    elif i == 1:
        fib[i] = 1
    else:
        fib[i] = fib[i - 1] + fib[i - 2]
print(fib[target])

Solution (Python):
def fibonacci(f, n):
    if n == 0 or n == 1:
        f[n] = 1
        return f[n]
    if f[n]:
        return f[n]
    f[n] = fibonacci(f, n - 2) + fibonacci(f, n - 1)
    return f[n]

n = int(input())
f = [None for i in range(n + 1)]
print(fibonacci(f, n))

Solution (Python):
n = int(input())
x, y = 1, 1
for i in range(n):
  x, y = y, x + y
print(x)

Solution (Python):
n = int(input())
fib = [1, 1] + [0] * n
for i in range(2, n+1):
    fib[i] = fib[i-1] + fib[i-2]
print(fib[n])

Solution (Python):
n = int(input())
fib = [1, 1] + [0 for i in range(44)]
for i in range(2, n + 1):
    fib[i] = fib[i - 1] + fib[i - 2]
print(fib[n])