corrected algorithm error
solve problem 5