Erlang Chocolates By Numbers
-module(chocolates_by_numbers).
-export([chocolates_by_numbers/2]).
chocolates_by_numbers(N, M) ->
G = gcd(N, M),
(N * M) div G div M.
gcd(N, M) when N rem M =:= 0 -> M;
gcd(N, M) -> gcd(M, N rem M).
This uses the greatest common divisor to figure out how many chocolates get eaten before the pattern repeats.