java - Long overflows : Fibonacci series -


i'm trying solve second euler problem (calculate sum of fibonacci numbers < 4 million) , far i've come this:

public class cctrial1 {     public static void fib(){     long  = 0, b = 1;     long  c = 0, sum = 0;     int = 1;     long = 0;     while(i < 400000){         c = + b;         sum = c;         = b;         b = c;         if(sum %2 == 0){             += sum;          }         i++;     }     system.out.println("count " +i);     system.out.println("last fib no " +sum);     system.out.println("sum " +even);     }      public static void main (string[] args){         fib();     }  } 

i have changed long , still overflow. can please tell me i'm going wrong?

the problem involves fibonacci terms less 4 million, not first 4 million fibonacci terms.

for example, 35th, 36th , 37th fibonacci numbers 5702887, 9227465 , 14930352; problem statement excludes them consideration, because greater 4000000.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -