-module(simple). -export([collect_simple/1]). try_div(_,[]) -> true; try_div(N,_) when N>0, N<3 -> true; try_div(N,[1|T]) -> try_div (N, T); try_div(N,[H|T]) -> Lim = 0.1+math:sqrt(N), if H>Lim -> true; N rem H == 0 -> false; true -> try_div (N,T) end. find_simple (I, N, Prev) when I > N -> Prev; find_simple (I, N, Prev) -> DivRes=try_div (I,Prev), if DivRes -> NewPrev=lists:append(Prev,[I]); true -> NewPrev = Prev end, find_simple (I+1, N, NewPrev). collect_simple(N) when N<1 -> []; collect_simple(N) -> find_simple (1, N, []).