Given a non-negative integer $m$ and a positive integer $n$, calculate $\lfloor \frac{m}{n} \rfloor$

157 Views Asked by At

Here is the problem:

  • I have a non-negative integer $m$ and a positive integer $n$
  • I would like to calculate $\lfloor \frac{m}{n} \rfloor$, $\lceil \frac{m}{n} \rceil$ and $m \bmod n$
  • But I want to achieve this without using $floor$, $ceiling$, $round$, $modulo$, $abs$, and $if$

Now, if I find a way to calculate $\lfloor \frac{m}{n} \rfloor$, then the rest is easy:

  • $\lceil \frac{m}{n} \rceil = \lfloor \frac{m+n-1}{n} \rfloor$
  • $m \bmod n = m-\lfloor \frac{m}{n} \rfloor n$

Unfortunately, I haven't been able to do so as of yet.

Instead, I have found a way to calculate $\lceil \frac{m}{n} \rceil = \frac{m}{n}+\frac{1}{2}+\frac{\arctan(-\tan(\pi(\frac{m}{n}+\frac{1}{2})))}{\pi}$

So at this point, I am still left with the original problem of finding a way to calculate $\lfloor \frac{m}{n} \rfloor$, where the only progress towards a solution being the fact that I might be able to do so using $\lceil \frac{m}{n} \rceil$.

Please keep in mind that $\lceil \frac{m}{n} \rceil$ doesn't necessarily yield the correct output for negative values of $\frac{m}{n}$. In particular, it yields an incorrect output for negative integers, so I cannot use $\lfloor \frac{m}{n} \rfloor = \lceil \frac{m-n+1}{n} \rceil$.

Any ideas?