Is this floor division expansion true for all positive integers?

77 Views Asked by At

Suppose you have 3 positive (non-zero) integers $n,x,y$. Is the following statement true?

$$ \left\lfloor\frac{n y}{x}\right\rfloor = y\left\lfloor\frac{n}{x}\right\rfloor+\left\lfloor\frac{y\left(n\bmod x\right)}{x}\right\rfloor $$

Throwing a large amount of numbers at it, it seems to hold, but I'm not able to prove it.

For reference, I'm trying to implement an algorithm which will involve multiplying two integers (which might overflow), then performing an integer division. I'm trying to break the multiplication up into two smaller multiplications.

2

There are 2 best solutions below

0
On BEST ANSWER

Write $n = ax + b$ where $b = (n \mod x)$, i.e. $a$ and $b$ are nonnegative integers with $b < n$, and $\lfloor \dfrac{n}{x} \rfloor = a$. Then $$\dfrac{ny}{x} = ay + \dfrac{by}{x}$$ which is your equation.

0
On

Yes, the given statement is true.

Let $n=x\cdot q+r\implies n\equiv r\pmod x$, where $q,r\in \mathbb{Z}$ and $0\le r<x-1$.

We have, $$\begin{align*} \left\lfloor\frac{(xq+r)y}{x}\right\rfloor&=y\left\lfloor\frac{(xq+r)}{x}\right\rfloor+\left\lfloor\frac{yr}{x}\right\rfloor \\ qy+\left\lfloor\frac{ry}{x}\right \rfloor &= qy+\left\lfloor\frac{yr}{x}\right\rfloor &&\left(\because \left\lfloor\frac{r}{x}\right\rfloor=0\right) \end{align*}$$ which is obviously true.