Less iterations to solve problem 5