Solved problem 5 with brute force.