maths.freeNumber Theory › Fermat's little theorem and Euler's theorem

Fermat's little theorem and Euler's theorem

aᵖ⁻¹ ≡ 1 (mod p), the totient, and fast modular arithmetic.

For prime p and a not divisible by p, aᵖ⁻¹ ≡ 1 (mod p); Euler generalises to a^φ(n) ≡ 1 (mod n). These collapse huge exponents: 2¹⁰⁰ mod 13 reduces via 2¹² ≡ 1. Picture it: the powers of 2 mod 13 cycling around a 12-hour clock. Think it: this is Lagrange's theorem in the group (ℤ/n)*.

Beispiel: 2^100 mod 13

2^100 mod 13

2,\ 100,\ 13

Schritt für Schritt

  1. 2^{100} \bmod 13

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

  2. 2 \equiv 2 \pmod{13}

    Reduce the base first.

  3. 100 = 1100100_2

    Write the exponent in binary: 7 squarings at most.

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

    Square the running power.

  5. 4^2 \equiv 3 \pmod{13}

    Square the running power.

  6. r \leftarrow r \cdot 3 \equiv 3 \pmod{13}

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

  7. 3^2 \equiv 9 \pmod{13}

    Square the running power.

  8. 9^2 \equiv 3 \pmod{13}

    Square the running power.

  9. 3^2 \equiv 9 \pmod{13}

    Square the running power.

  10. r \leftarrow r \cdot 9 \equiv 1 \pmod{13}

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

  11. 9^2 \equiv 3 \pmod{13}

    Square the running power.

  12. r \leftarrow r \cdot 3 \equiv 3 \pmod{13}

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

  13. 2^{100} \equiv 3 \pmod{13}

    Done.

Die Antwort aufzeigen
2^{100} \bmod 13 = 3

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: Fermat's little theorem and Euler's theorem

  1. Reduce the base mod n.
  2. Reduce the exponent mod p − 1 (prime) or mod φ(n) (general) — Fermat/Euler.
  3. Finish with repeated squaring on what remains.

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.

Versuch es selbst.

Mehr in Number Theory