Erlang Count Factors
-module(count_factors).
-export([count_factors/1]).
count_factors(N) ->
count_factors(N, 1, 0).
count_factors(N, I, Count) when I * I < N ->
NewCount = case N rem I =:= 0 of
true -> Count + 2;
false -> Count
end,
count_factors(N, I + 1, NewCount);
count_factors(N, I, Count) when I * I =:= N ->
Count + 1;
count_factors(_, _, Count) ->
Count.
This checks divisors in pairs up to the square root, which keeps the work much smaller than testing every number.