Problem Introduction
The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_{i-1}+F_{i-2}\) for $ i \geq 2$.
Problem Description
Task.Given an integer \(n\),find the \(n\)th Fibonacci number \(F_n\).
Input Format.The input consists of a single integer \(n\).
Constraints.\(0 \leq n \leq 45\).
Output Format.Output \(F_n\).
Sample 1.
Input:
3
Output
2
Sample 2.
Input:
10
Output:
55
Solution
# Uses python3
def calc_fib(n):
x,y = 0,1
while n > 0:
x,y,n = y,x+y,n-1
return x
n = int(input())
print(calc_fib(n))