Pages

Tuesday, September 8, 2009

Euler Problem 28 solution

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

public class Problem_28 {
 public static void main(String[] args) {
  int sum = 1, diag = 1, size = 1001;

  for (int i = 2; i < size; diag += i * 4, i += 2)
   sum += 4 * diag + 10 * i;

  System.out.println(sum);
 }
}

No comments:

Post a Comment