Problems > Sum of the First K Fibonacci Numbers

Sum of the First K Fibonacci Numbers

Difficulty: 1100 2000 ms 128 MB

math

Using the sequence 1, 2, 3, 5, 8, ... print the sum of its first K terms.

Input: one integer K.

Output: the sum (it equals F(K+2) − 2 in this indexing).

Constraints:

  • 1 ≤ K ≤ 85

Sample Tests

Input 1
4
Output 1
11
Input 2
1
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.