Solution for Problem #36 (Brute-force)