, thus . Now take and add to both sides, obtaining . But we've seen that , so we are done. □) The modulo with offset is implemented in Mathematica as . Implementing other modulo definitions using truncation Despite the mathematical elegance of Knuth's floored division and Euclidean division, it is generally much more common to find a truncated division-based modulo in programming languages. Leijen provides the following algorithms for calculating the two divisions given a truncated integer division: /* Euclidean and Floored divmod, in the style of C's ldiv() */ typedef struct { /* This structure is part of the C stdlib.h, but is reproduced here for clarity */ long int quot; long int rem; } ldiv_t; /* Euclidean division */ inline ldiv_t ldivE(long numer, long denom) { /* The C99 and C++11 languages define both of these as truncating. */ long q = numer / denom; long r = numer % denom; if (r < 0) { if (denom > 0) { q = q - 1; r = r + denom; } else { q = q + 1; r = r - denom; } } return (ldiv_t){.quot = q, .rem = r}; } /* Floored division */ inline ldiv_t ldivF(long numer, long denom) { long q = numer / denom; long r = numer % denom; if ((r > 0 && denom < 0) || (r < 0 && denom > 0)) { q = q - 1; r = r + denom; } return (ldiv_t){.quot = q, .rem = r}; } For both cases, the remainder can be calculated independently of the quotient, but not vice versa. The operations are combined here to save screen space, as the logical branches are the same. See also Modulo (disambiguation) and modulo (jargon) – many uses of the word modulo, all of which grew out of Carl F. Gauss's introduction of modular arithmetic in 1801. Modulo (mathematics), general use of the term in mathematics Modular exponentiation Turn (angle) Notes References External links Modulorama, animation of a cyclic representation of multiplication tables (explanation in French) Computer arithmetic Articles with example C++ code Operators (programming) Modular arithmetic Operations on numbers de:Division mit Rest#Modulo