Erlang Count Div
-module(count_div).
-export([count_div/3]).

count_div(A, B, K) ->
    FirstDiv = case A rem K of
        0 -> A;
        R -> A + (K - R)
    end,
    LastDiv = B - (B rem K),
    (LastDiv - FirstDiv) div K + 1.

This counts how many numbers in a range are divisible by K without looping through every value.