Sum of even Fibbonacci

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 1, the first 10 terms will be:

1,1, 2, 3, 5, 8, 13, 21, 34, 55 .....

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.


Try other problems here .


The answer is 4613732.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
public class Main {
    public static void main(String[] args) {
        int old=1,present=2,next;
        int sum=0;
        while(present<4_000_000){
            if (present%2==0) {
                sum += present;
            }
            next = old + present;
            old = present;
            present=next;
        }
        System.out.println("the Sum is: " + sum);
    }

} 

Do you know how to use the theory of fibonacci sequence to answer this problem directly?

Hint: Every third number is even.

Calvin Lin Staff - 4 years ago

Log in to reply

Sum of even numbers is half of sum of all numbers. )))

Hasmik Garyaka - 3 years, 8 months ago

Log in to reply

Great insights. That allows us to conclude that the sum of the even terms up to F 3 n F_{3n} is F 3 n + 2 1 2 \frac{ F_{3n+2} - 1 } { 2} .

Alternatively, we can use Binet's formula and sum up the Geometric progressions accordingly.

Calvin Lin Staff - 3 years, 8 months ago

And sum(from 1 to n)=F(n + 2) - 1.

Hasmik Garyaka - 3 years, 8 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...