maths.free › Number 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.
Contoh yang dikerjakan: 3^100 mod 7
Langkah demi langkah
- 3^{100} \bmod 7
Never compute the huge power. Reduce after every multiplication (repeated squaring).
- 3 \equiv 3 \pmod{7}
Reduce the base first.
- 100 = 1100100_2
Write the exponent in binary: 7 squarings at most.
- 3^2 \equiv 2 \pmod{7}
Square the running power.
- 2^2 \equiv 4 \pmod{7}
Square the running power.
- r \leftarrow r \cdot 4 \equiv 4 \pmod{7}
This bit is 1: multiply the result by the current power.
- 4^2 \equiv 2 \pmod{7}
Square the running power.
- 2^2 \equiv 4 \pmod{7}
Square the running power.
- 4^2 \equiv 2 \pmod{7}
Square the running power.
- r \leftarrow r \cdot 2 \equiv 1 \pmod{7}
This bit is 1: multiply the result by the current power.
- 2^2 \equiv 4 \pmod{7}
Square the running power.
- r \leftarrow r \cdot 4 \equiv 4 \pmod{7}
This bit is 1: multiply the result by the current power.
- 3^{100} \equiv 4 \pmod{7}
Done.
Tunjukkan jawapan
Symbols used here
n divides a − b; a and b have the same remainder.
Both signs at once: x = 3 ± 2 means 5 and 1.
Inequalities that allow equality; < and > exclude it.
What is left after dividing a by n.
The exponent b must be raised to for x; ln uses base e.
Add a_k for k = 1 up to n.
Multiply a_k for k = 1 up to n.
Naturals, integers, rationals, reals, complex numbers.
b is a multiple of a; the largest number dividing both.
Count of 1..n coprime to n; number of primes up to x.
The remainders 0…n−1 with clock arithmetic.
How to: Modular arithmetic
- Never compute the huge power. Reduce after every multiplication (repeated squaring).
- Reduce the base first.
- Write the exponent in binary: 7 squarings at most.
- Square the running power.
- Square the running power.
- This bit is 1: multiply the result by the current power.
- Square the running power.
- 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.
Cubalah sendiri
Lebih dalam Number Theory
Prime factorisationPrime numbersGCD and LCMDivisorsSequencesNumber basesDiophantine equationsFermat's little theorem and Euler's theoremRSA: cryptography from number theory