Given a number K, the task is to find the sum of numbers at the Kth level of the Fibonacci triangle.
Input: K = 3 Output: 10 Explanation: Fibonacci triangle till level 3: 0 1 1 2 3 5 Sum at 3rd level = 2 + 3 + 5 = 10 Input: K = 2 Output: 2 Explanation: Fibonacci triangle till level 3: 0 1 1 Sum at 3rd level = 1 + 1 = 2
- Till Kth level, i.e. from level [1, K-1], count of Fibonacci numbers already used can be computed as:
cnt = N(Level 1) + N(Level 2) + N(Level 3) + ... + N(Level K-1) = 1 + 2 + 3 + ... + (K-1) = K*(K-1)/2
- Also, we know that the Kth level will contain K Fibonacci numbers.
- Therfore we can find the numbers in the Kth level as Fibonacci numbers in the range [(cnt + 1), (cnt + 1 + K)].
- We can find the sum of Fibonacci numbers in a range in O(1) time using Binet’s Formula.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sum of all the numbers present at given level in Pascal's triangle
- Find the numbers present at Kth level of a Fibonacci Binary Tree
- Sum of all the numbers present at given level in Modified Pascal’s triangle
- Program to print Fibonacci Triangle
- Maximum of all the integers in the given level of Pascal triangle
- Non Fibonacci Numbers
- GCD and Fibonacci Numbers
- Sum of Fibonacci Numbers
- Even Fibonacci Numbers Sum
- C Program for Fibonacci numbers
- Prime numbers and Fibonacci
- Alternate Fibonacci Numbers
- Program for Fibonacci numbers
- Generalized Fibonacci Numbers
- The Magic of Fibonacci Numbers
- Sum of Fibonacci Numbers in a range
- Sum of squares of Fibonacci numbers
- Find the sum of first N odd Fibonacci numbers
- Sum of all the numbers in the Nth row of the given triangle
- Remove all the fibonacci numbers from the given array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.