solve Problem#9 by brute force