Pages

Tuesday, September 8, 2009

Euler Problem 2 solution

Time (s): ~0.001
package margusmartseppcode.From_1_to_9;

public class Problem_2 {
 static final double gold_r = Math.pow((1 + Math.sqrt(5)) / 2, 3);

 public static void main(String[] args) {
  long size = 4000000, sum = 0;
  double f = 2;

  for (; f < size; f = Math.round(f * gold_r))
   sum += f;

  System.out.println(sum);
 }
}

No comments:

Post a Comment