#K92737. Sum of Fibonacci Numbers
Sum of Fibonacci Numbers
Sum of Fibonacci Numbers
Given a positive integer N
, compute the sum of the Fibonacci numbers from \(F(0)\) to \(F(N)\). The Fibonacci sequence is defined as follows:
[ F(0)=0,\quad F(1)=1,\quad \text{and}\quad F(n)=F(n-1)+F(n-2)\quad \text{for } n\ge2. ]
If the input N
is negative, the output should be 0
.
Example:
Input: 5 Output: 12</p>Explanation: The Fibonacci numbers from F(0) to F(5) are: 0, 1, 1, 2, 3, 5. Their sum is 0+1+1+2+3+5=12.
inputFormat
The input consists of a single integer N
provided via standard input.
outputFormat
Output a single integer: the sum of the Fibonacci numbers from \(F(0)\) through \(F(N)\). If N
is negative, output 0.
5
12