solved euler 39, runtime is slow, could optimize