LCM of 1 to n by 51b

-module(l).
-export([m/0]).
m()->case io:fread('',"~d")of{_,[X]}->io:write(f(X)),io:nl(),m();_->0end.
f(1)->1;f(X)->Y=f(X-1),X*Y div g(X,Y).
g(X,0)->X;g(X,Y)->g(Y,X rem Y).

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page