Open In App

Java Program to Find Sum of Fibonacci Series Numbers of First N Even Indexes

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
5 Likes
Like
Report

For a given positive integer N, the purpose is to find the value of F2 + F4 + F6 +………+ F2n till N number. Where Fi indicates the i'th Fibonacci number.

The Fibonacci Series is the numbers in the below-given integer sequence.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ……

Examples:

Input: n = 4
Output: 33
N = 4, So here the fibonacci series will be produced from 0th term till 8th term:
0, 1, 1, 2, 3, 5, 8, 13, 21
Sum of numbers at even indexes = 0 + 1 + 3 + 8 + 21 = 33.

Input: n = 7
Output: 609
0 + 1 + 3 + 8 + 21 + 55 + 144 + 377 = 609.

Approach 1:

Find all Fibonacci numbers till 2n and add up only the even indices.


Output
Even sum of fibonacci series till number 11 is: 28656

Time Complexity: O(n)

Auxiliary Space: O(n) as it is using an auxiliary array fib

Approach 2:

It can be clearly seen that the required sum can be obtained thus:
2 ( F2 + F4 + F6 +………+ F2n ) = (F1 + F2 + F3 + F4 +………+ F2n) – (F1 – F2 + F3 – F4 +………+ F2n)

Now the first term can be obtained if we put 2n instead of n in the formula given here.

Thus F1 + F2 + F3 + F4 +………+ F2n = F2n+2 – 1.

The second term can also be found if we put 2n instead of n in the formula given here

Thus, F1 – F2 + F3 – F4 +………- F2n = 1 + (-1)2n+1F2n-1 = 1 – F2n-1.

So, 2 ( F2 + F4 + F6 +………+ F2n)
= F2n+2 – 1 – 1 + F2n-1
= F2n+2 + F2n-1 – 2
= F2n + F2n+1 + F2n+1 – F2n – 2
= 2 ( F2n+1 -1)
Hence, ( F2 + F4 + F6 +………+ F2n) = F2n+1 -1 .

The task is to find only F2n+1 -1.

Below is the implementation of the above approach:


Output
Even indexed Fibonacci Sum upto 8 terms: 1596

Time Complexity: O(log n)

Auxiliary Space: O(MAX) because using an auxiliary array


Article Tags :
Practice Tags :

Similar Reads