# Modular Arithmetic

## TLDR

When we divide two integers we will have an equation that looks like the following:

<figure><img src="https://1983523492-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0nwEx8a60yETwfNYnenT%2Fuploads%2FkBC8Gtd9Qv3NrPTzJaPH%2Fimage.png?alt=media&#x26;token=e47f8b8b-bf3d-4100-b263-a9111e42aa8b" alt=""><figcaption></figcaption></figure>

Sometimes, we are only interested in what the **remainder** is when we divide A by B.\
For these cases there is an operator called the modulo operator (abbreviated as mod).

Using the same A, B, Q, and R as above, we would have: **`A mod B = R.`**&#x20;

<figure><img src="https://1983523492-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0nwEx8a60yETwfNYnenT%2Fuploads%2FABpDDXmrgoBKPOt79FDG%2Fimage.png?alt=media&#x26;token=ae9b0f2b-42ab-45ef-8b80-8b7bf3631d64" alt=""><figcaption></figcaption></figure>

### Visualize modulus with clocks

<figure><img src="https://1983523492-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0nwEx8a60yETwfNYnenT%2Fuploads%2FH0l48SRDw9cRaqQxDBh6%2Fimage.png?alt=media&#x26;token=b759bf3a-8976-4566-91ba-2f9d5d16d2a5" alt=""><figcaption></figcaption></figure>

#### Increasing by divisor

<figure><img src="https://1983523492-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0nwEx8a60yETwfNYnenT%2Fuploads%2Fyv2PAwsBioTQ5eT9JXQC%2Fimage.png?alt=media&#x26;token=5dd38f7e-ba54-4372-b634-d5aa87ad0ec2" alt=""><figcaption></figcaption></figure>

#### Congruence Modulo

<figure><img src="https://1983523492-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0nwEx8a60yETwfNYnenT%2Fuploads%2FeY7ESXo03JQ3C2gHVVWe%2Fimage.png?alt=media&#x26;token=f9ebfe0e-1193-4551-a01f-66020ce91839" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1983523492-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0nwEx8a60yETwfNYnenT%2Fuploads%2FSpD8w2cyJ2UBCzmC24bv%2Fimage.png?alt=media&#x26;token=6292bcf2-4837-431d-8f88-57009c2d91e9" alt=""><figcaption></figcaption></figure>
