Project Euler Problem 107 - Kruskal Version