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:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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
- Sum of Fibonacci Numbers
- GCD and Fibonacci Numbers
- Non Fibonacci Numbers
- Even Fibonacci Numbers Sum
- Prime numbers and Fibonacci
- Sum of Fibonacci Numbers in a range
- Alternate Fibonacci Numbers
- Sum of squares of Fibonacci numbers
- The Magic of Fibonacci Numbers
- Find the sum of first N odd Fibonacci numbers
- Program for Fibonacci numbers
- C Program for Fibonacci numbers
- Sum of all the numbers in the Nth row of the given triangle
- Find the GCD of N Fibonacci Numbers with given Indices
- 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.