[algorithm.search_n] Fix search_n's complexity violation.

According to document, at most last - first applications of the corresponding predicate,
but (last - first) * count applications.