-module(factor).
-export([fact/1]).
% c('factor').
% factor:fact(123456723456789).
fact(1) ->
[];
fact(N) ->
% io:format("~w
", [N]),
M = next_factor(N, 2, N rem 2),
[ M | fact(N div M) ].
% find the next factor
next_factor(_, M, 0) ->
M;
next_factor(N, N, _) ->
N;
next_factor(N, M, _) ->
next_factor(N, M+1, N rem (M+1)).Add a code snippet to your website: www.paste.org