Modular arithmetic

Math · Discrete Math

Question 1 of 10

0

    What is ?

    Decimals (0.75 or 0,75), fractions (3/4) and mixed numbers (1 1/2) are accepted. Do not use thousands separators.

    How to type your answer
    • Fractions: 3/4. Mixed numbers: 1 1/2.
    • Decimals with a point or a comma: 0.75 or 0,75.
    • Negative numbers start with a minus: -3/4.
    • Percentages need the % sign: 75%.

    Stuck? Read the explanation

    Unlocks at a streak of 5 correct answers in a row.

    Print a free worksheet (PDF)

    Embed this practice on your site or class page

    Paste this HTML into your page. Students practise right there; it is free and needs no account.

    Modular arithmetic explained

    Modular arithmetic is arithmetic on remainders. It asks what is left over after dividing by a fixed number, which is why it describes clocks, calendars and the days of the week.

    The result of a mod na \bmod n is always a whole number from 0 to n−1n - 1. Two numbers are congruent modulo n when they leave the same remainder when divided by n, written a≡b(modn)a \equiv b \pmod{n}. To work with large numbers, you can take remainders at any stage: (a+b) mod n(a + b) \bmod n equals ((a mod n)+(b mod n)) mod n\big((a \bmod n) + (b \bmod n)\big) \bmod n, and the same idea works for multiplication. This keeps the numbers small and is the basis of many codes and cryptography methods.

    Worked example

    Find 47 mod 1247 \bmod 12, −7 mod 5-7 \bmod 5 and (23+19) mod 7(23 + 19) \bmod 7.

    1. 12×3=3612 \times 3 = 36 and 47−36=1147 - 36 = 11, so 47 mod 12=1147 \bmod 12 = 11.
    2. −7=5×(−2)+3-7 = 5 \times (-2) + 3, so −7 mod 5=3-7 \bmod 5 = 3.
    3. 23 mod 7=223 \bmod 7 = 2 and 19 mod 7=519 \bmod 7 = 5, so (23+19) mod 7=(2+5) mod 7=7 mod 7=0(23 + 19) \bmod 7 = (2 + 5) \bmod 7 = 7 \bmod 7 = 0.

    A common mistake is giving −7 mod 5-7 \bmod 5 as −2-2. Some programming languages return −2-2 from their remainder operator, but the answer must lie between 0 and n−1n - 1, so the correct value is 3.

    What you will practise

    New numbers every time you practise. Levels: Easy, Medium, Hard. Each answer is followed by a worked explanation.

    Example questions

    • Easy

      What is 10 mod 8?

    • Medium

      What is -10 mod 12?

    • Hard

      What is (17 × 39 + 28) mod 20?