If I denote by $\alpha$ the number of numbers divisible by $n$ in the interval $[k,m]$ it seems that this formula already works

$$\left\lfloor\frac mn\right\rfloor-\Big\lceil\frac kn\Big\rceil+1=\alpha$$

but it's not clear to me why it works, and I haven't found a book that explains it, maybe it's too obvious but I can't see it. Can someone explain or give me some bibliography?