solve by BF, there is a big difference between O(N) and O(sqrt(N))