Return the n-th Fibonacci number, where F(0) = 0, F(1) = 1 and F(k) = F(k-1) + F(k-2).
Input
A single integer n.
Output
F(n).
Return the n-th Fibonacci number, where F(0) = 0, F(1) = 1 and F(k) = F(k-1) + F(k-2).
A single integer n.
F(n).
Example 1
0
0
F(0) = 0.
Example 2
1
1
F(1) = 1.
Example 3
10
55
F(10) = 55.
Build up iteratively from F(0) and F(1) — no recursion needed.
Keep only the last two values as you go.
Iterate n times, keeping the previous two Fibonacci numbers (a, b) and stepping (a, b) → (b, a + b).
n = int(input())
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
print(a)
Tell us what needs to change, who it affects and any important deadline. We will review the context and reply with useful next questions.