Problem 9 Brute Force Solution