Fibonacci Number

Practice this coding question on Coding Gurukul.

Problem statement

An animation assigns frame counts using the Fibonacci sequence. Each new stage uses the combined frame counts of the previous two stages. Your task Compute F(n), where F(0) = 0, F(1) = 1, and F(n) = F(n - 1) + F(n - 2) for n >= 2. Important details The stage number is an index, not the number of sequence entries to print. Return just that stage's value. The first two indices must be handled directly. Track the previous two values while moving forward so repeated subproblems do not cause exponential work. Print an exact integer without a modulus; the input bound keeps the result within a signed 64-bit integer. Worked example For n = 7, the sequence through that index is 0, 1, 1, 2, 3, 5, 8, 13. Therefore the requested output is 13.

Input format

One integer n.

Output format

Print F(n).

Constraints

0 <= n <= 45.

Sample input

7

Sample output

13

Sign in to run or submit a solution in C++, Java or Python.