maths.freeNumber Theory › Modular arithmetic

Modular arithmetic

Remainders, congruences, fast powers and modular inverses.

Arithmetic on a clock: only the remainder matters. Huge powers are tamed by reducing after every multiplication (repeated squaring), and a modular inverse — the number that undoes multiplication — comes from the extended Euclidean algorithm. This is the engine behind RSA encryption.

İşlediği örnek: 3^100 mod 7

3^100 mod 7

3,\ 100,\ 7

Adım adım

  1. 3^{100} \bmod 7

    Never compute the huge power. Reduce after every multiplication (repeated squaring).

  2. 3 \equiv 3 \pmod{7}

    Reduce the base first.

  3. 100 = 1100100_2

    Write the exponent in binary: 7 squarings at most.

  4. 3^2 \equiv 2 \pmod{7}

    Square the running power.

  5. 2^2 \equiv 4 \pmod{7}

    Square the running power.

  6. r \leftarrow r \cdot 4 \equiv 4 \pmod{7}

    This bit is 1: multiply the result by the current power.

  7. 4^2 \equiv 2 \pmod{7}

    Square the running power.

  8. 2^2 \equiv 4 \pmod{7}

    Square the running power.

  9. 4^2 \equiv 2 \pmod{7}

    Square the running power.

  10. r \leftarrow r \cdot 2 \equiv 1 \pmod{7}

    This bit is 1: multiply the result by the current power.

  11. 2^2 \equiv 4 \pmod{7}

    Square the running power.

  12. r \leftarrow r \cdot 4 \equiv 4 \pmod{7}

    This bit is 1: multiply the result by the current power.

  13. 3^{100} \equiv 4 \pmod{7}

    Done.

Cevabı açıkla.
3^{100} \bmod 7 = 4

Symbols used here

a \equiv b \pmod n
congruent modulo n
n divides a − b; a and b have the same remainder.
\pm
plus or minus
Both signs at once: x = 3 ± 2 means 5 and 1.
\leq,\ \geq
less/greater than or equal
Inequalities that allow equality; < and > exclude it.
a \bmod n
remainder
What is left after dividing a by n.
\log_b x,\ \ln x
logarithm, natural log
The exponent b must be raised to for x; ln uses base e.
\sum_{k=1}^{n} a_k
summation
Add a_k for k = 1 up to n.
\prod_{k=1}^{n} a_k
product
Multiply a_k for k = 1 up to n.
\mathbb{N},\ \mathbb{Z},\ \mathbb{Q},\ \mathbb{R},\ \mathbb{C}
number sets
Naturals, integers, rationals, reals, complex numbers.
a \mid b,\ \gcd(a,b)
divides, greatest common divisor
b is a multiple of a; the largest number dividing both.
\varphi(n),\ \pi(x)
Euler's totient, prime-counting function
Count of 1..n coprime to n; number of primes up to x.
\mathbb{Z}/n\mathbb{Z},\ \mathbb{Z}_n
integers modulo n
The remainders 0…n−1 with clock arithmetic.

How to: Modular arithmetic

  1. Never compute the huge power. Reduce after every multiplication (repeated squaring).
  2. Reduce the base first.
  3. Write the exponent in binary: 7 squarings at most.
  4. Square the running power.
  5. Square the running power.
  6. This bit is 1: multiply the result by the current power.
  7. Square the running power.
  8. Square the running power.

Questions people ask

Why are primes so important?

Every integer factors into primes in exactly one way, so primes are the atoms of multiplication. Cryptography relies on that factoring being easy to state and hard to do.

How do I tell whether a big number is prime?

Trial division up to the square root works for small numbers. For large ones, probabilistic tests (Miller–Rabin) give an answer that is wrong with negligible probability, and deterministic tests (AKS) exist but are slower.

Kendini dene.

Daha fazlası Number Theory