I want to understand how -1 % 5 = 4.
I already know that 1 % 5 = 1 and 2 % 5 = 2 and so on. Please explain this when it is negative as in the previous example.
I want to understand how -1 % 5 = 4.
I already know that 1 % 5 = 1 and 2 % 5 = 2 and so on. Please explain this when it is negative as in the previous example.
On
It seems that you are asking why $-1 \equiv 4 \bmod 5$.
Let $m$ be a positive integer. For any integer $a$, there is a unique integer $b \in \{0, \dots, m - 1\}$ such that $a - b$ is a multiple of $m$ and we write $a \equiv b \bmod m$, or in the notation you are using, $a\% m = b$.
In this particular example, $-1 - 4 = - 5$ which is a multiple of $5$; here $a = -1$, $b = 4$ and $m = 5$. So $-1 \equiv 4 \bmod 5$, or $-1\%5 = 4$.
In general, when you are trying determine a negative number modulo a positive number, you can just keep adding the modulus until you get a non-negative number.
Example: To determine $-36 \bmod 7$, we do the following computations
\begin{align*} -36 + 7 &= -29\\ -29 + 7 &= -22\\ -22 + 7 &= -15\\ -15 + 7 &= -8\\ -8 + 7 &= -1\\ -1 + 7 &= 6\ \checkmark \end{align*}
So $-36 \equiv 6 \bmod 7$.
The mod function defined as the amount by which number exceeds the largest integer multiple of the divisor that is not greater than that number. And an illustration of this definition.
So,
Mod[1, 5] = 1andMod[-1, 5] = 4.