Segundo Problema del Proyecto Euler

Problem 2

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

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

Find the sum of all the even-valued terms in the sequence which do not exceed four million.

Bueno el problema pensándolo así es bastante sencillo. Recuerdo que me enseñaron a utilizar la recursividad, pues aquí expongo mi método recursivo hecho en Java


public static long resultado(long a, long b, long sum) {
    if (b>=4000000)
        return sum;
    sum += (b%2==0) ? b : 0;
    return resultado(b,a+b,sum);

Solamente hay que llamarlo con


y listo esto imprimirá en la pantalla el resultado… smile_regular

Interesante como solo unas cuantas líneas puede procesar una serie infinita… smile_wink

Propongan sus algoritmos, para así aprender de todos…


1 Response to “Segundo Problema del Proyecto Euler”

  1. 1 Unknown 2008-09-23 at 7:52 AM

    Hi,Do you need advertising displays, screen advertisings, digital sign, digital signages and LCDs? Please go have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.
    amberdigital Contact Us[giaffhjaccabdg]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog Stats

  • 173,748 hits

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 18 other followers

May 2008
« Apr   Jun »

Grendon’s Twitter

MSP Ecuador’s Twitter

Error: Please make sure the Twitter account is public.


%d bloggers like this: