# Use of "modulo" operation in place of integer division

And got an answer: The row is :$$r = \left\lfloor \frac{n-1}{t} \right\rfloor + 1$$

This involves dividing by int. variables like in computer programming. However, I am wondering if there is a formula that does not involve dividing by int. variables and just uses modulo.

My attempt:

n - ((n-1)%t) + 1

Doesn't seem to work. Help would be appreciated!

• I've attempted to make the title more informative, while staying true to the intent of the problem. Feel free to re-title if I've missed the point. Feb 27, 2013 at 23:57

$\left\lfloor\frac{n-1}t\right\rfloor$ is not (n-1)%t. It is int((n-1)/t).
If you really want to "just use modulo" you can apply the identity that says that $$\left\lfloor\frac ab\right\rfloor = \frac{a-a\bmod b}b,$$ which says that you can use (n-1-(n-1)%t) / t. But that seems a little bit silly.
• The real identity is that $a = b\cdot\left\lfloor\frac ab\right\rfloor + a\bmod b$. When you divide $a$ by $b$, there is a quotient, which is $\left\lfloor\frac ab\right\rfloor$, and a remainder, which is $a\bmod b$. You needed the quotient, not the remainder.
• $\left\lfloor\frac52\right\rfloor = 2$, so $5\bmod 2 = 5 - 2\left\lfloor\frac52\right\rfloor = 5 -2\cdot2 = 1$, as you said.