> For the complete documentation index, see [llms.txt](https://davidjosearaujo.gitbook.io/notes-mcs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://davidjosearaujo.gitbook.io/notes-mcs/applied-cryptography/rsa-and-related-subjects/modular-arithmetic.md).

# Modular Arithmetic

<table><thead><tr><th width="178">Notation</th><th>Meaning</th></tr></thead><tbody><tr><td><span class="math">m \mid n</span></td><td><span class="math">m</span> divides <span class="math">n</span></td></tr><tr><td><span class="math">m \nmid n</span></td><td><span class="math">m</span> does not divide <span class="math">n</span></td></tr><tr><td><span class="math">n \equiv r (mod m)</span></td><td><span class="math">m \mid (n-r)</span>, that is, as <span class="math">m</span> divides <span class="math">n-r</span>, <span class="math">n</span> and <span class="math">r</span> have the same remainder when divided by <span class="math">m</span></td></tr><tr><td><span class="math">\lfloor x \rfloor</span></td><td>floor function: largest integer not larger than x</td></tr><tr><td><span class="math">n mod m</span></td><td>(binary operator) remainder of <span class="math">n</span> when divided by <span class="math">m</span> (<span class="math">m</span> is called the modulus, which we assume here to be a positive integer). Equal to <span class="math">n-m \lfloor \frac{n}{m} \rfloor</span>. Note that <span class="math">0 \le r \lt m</span>. In <code>C, Python, Java</code>, and <code>pari-gp</code>, it can be computed using using the <code>%</code> binary operator (applied to unsigned integers).</td></tr><tr><td><span class="math">gcd(a,b)</span></td><td>gratest common divisor of <span class="math">a</span> and <span class="math">b</span>.</td></tr><tr><td><span class="math">lcm(a,b)</span></td><td>least common multiple of <span class="math">a</span> and <span class="math">b</span>; equal to <span class="math">ab/ gcd(a,b)</span>.</td></tr><tr><td><span class="math">\mathbb{Z}_m</span></td><td>set of equivalence classes modulo <span class="math">m</span>; slightly abusing the mathematical notation for equivalence classes, <span class="math">\mathbb{Z}_m = \lbrace 0, 1, ..., m-1 \rbrace</span>.</td></tr></tbody></table>

## Examples

<figure><img src="https://3450804385-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRIg06sTkCh60KyuJiT39%2Fuploads%2FKg911lQiz2cXqqGZJF5O%2Fa.png?alt=media&amp;token=72ada6f9-4c74-4a36-b3a5-4196205e2b87" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3450804385-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRIg06sTkCh60KyuJiT39%2Fuploads%2FP0WGrjU3xtR3ZGXJOir5%2Fa.png?alt=media&amp;token=555ea990-a415-412c-828a-1a1d215fa79e" alt=""><figcaption></figcaption></figure>
