Solved problem 40 with bruteforce.