package margusmartseppcode.From_40_to_49; import java.util.HashSet; import java.util.Set; public class Problem_44 { public static void main(String[] args) { Set<integer> set = new HashSet<integer>(); int p[] = new int[10000]; int i = 0, j = 0; boolean out = false; for (i = 1; i < 10000; i++) set.add(p[i] = (i * 3 * i - i) / 2); for (i = 1; i < 10000 && !out; i++) for (j = 1; j < i && !out; j++) if (set.contains(p[i] + p[j]) && set.contains(p[i] - p[j])) out = true; System.out.println(p[i] - p[j]); } }
Sunday, September 13, 2009
Euler Problem 44 solution
Time (s): ~0.294
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment