fork(1) download
  1. /* package whatever; // don't place package name! */
  2. import java.io.IOException;
  3.  
  4. import java.math.BigInteger;
  5. /* The class name doesn't have to be Main, as long as the class is not public. */
  6. class Main
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. BigInteger sum = BigInteger.ZERO;
  11. BigInteger[] series = new BigInteger[400];
  12.  
  13. // long[] series = new long[4000000];
  14.  
  15. // create first 2 series elements
  16. series[0] = BigInteger.valueOf(1);
  17. series[1] = BigInteger.valueOf(2);
  18.  
  19. // create the Fibonacci series and store it in an array
  20. for (int i = 2; i < series.length; i++) {
  21. series[i] = series[i - 1].add(series[i - 2]);
  22. if (series[i].mod(BigInteger.valueOf(2)) == BigInteger.valueOf(0)) {
  23. sum = sum.add(series[i]); // error here
  24. }
  25.  
  26. }
  27. System.out.println("Fibonacci Series sum " + sum); // error here
  28. }
  29. }
Success #stdin #stdout 0.08s 380160KB
stdin
1
2
10
42
11
stdout
Fibonacci Series sum 142406149054244805878994468840730497807690044391152445493238597822984635702016161948