is there a formula for modulo
I have been trying to find a formula for modulo for a long time now. I was wondering, is this even possible? I know there are lot's of solutions for this problem in computer science but is there a solution for this problem in arithmetics? I mean is there a function that uses only arithmetics actions that can solve this problem? (I mean actions like $\log$ or $\sqrt{}$ or something like that)
Solution 1:
If your definition of “arithmetics actions” includes the floor function, then this is straightforward:
$a \text{ mod } b = a - b ⌊\frac{a}{b}⌋ $
(Assuming you want the semantics of Python's %
operator, as opposed to C's.)
Solution 2:
Only formula I know of for mod is:$$n\hspace{1mm}mod\hspace{1mm}2 = \frac{1+(-1)^{n-1}}{2} $$