Pages

Tuesday, September 8, 2009

Euler Problem 6 solution

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

public class Problem_6 {
 public static void main(String[] args) {
  int size = 100;
  long qos = (int) Math.pow(size * (size + 1) / 2, 2);
  long soq = size * (size + 1) * (2 * size + 1) / 6;

  System.out.println(qos - soq);
 }
}

No comments:

Post a Comment