Modular Arithmetic Calculator

Explore modular arithmetic with comprehensive calculations, congruences, and number theory operations. Perfect for cryptography and discrete mathematics.

Results

Select an operation and enter values to see results

Step-by-Step Solution

Detailed steps will appear here after calculation

Multiplication Table (mod n)

Properties & Analysis

Properties will be shown after calculation

Modular Arithmetic Fundamentals

Modular arithmetic is a system of arithmetic for integers where numbers "wrap around" after reaching a certain value called the modulus.

Basic Concepts

Congruence

Two integers a and b are congruent modulo m if their difference is divisible by m.

Notation: a ≡ b (mod m)

Example: 17 ≡ 5 (mod 12) because 17 - 5 = 12

Modulo Operation

The modulo operation finds the remainder after division.

Notation: a mod m = r

Example: 17 mod 12 = 5

Equivalence Classes

All integers congruent to each other modulo m form an equivalence class.

Example: [2]₅ = {..., -8, -3, 2, 7, 12, ...}

Residue System

A complete residue system modulo m is a set of m integers, no two congruent modulo m.

Example: {0, 1, 2, 3, 4} is a complete residue system mod 5

Modular Operations

Basic Properties

Modular Inverse

The modular inverse of a modulo m is a number x such that (a × x) ≡ 1 (mod m).

Advanced Topics

Chinese Remainder Theorem

If m₁, m₂, ..., mₖ are pairwise coprime, then the system of congruences:

has a unique solution modulo M = m₁ × m₂ × ... × mₖ.

Euler's Theorem

If gcd(a, n) = 1, then a^φ(n) ≡ 1 (mod n), where φ(n) is Euler's totient function.

Fermat's Little Theorem

If p is prime and gcd(a, p) = 1, then a^(p-1) ≡ 1 (mod p).

Applications

Algorithms

Fast Modular Exponentiation

Computes a^b mod m efficiently using binary representation of the exponent:

  1. Initialize result = 1
  2. While b > 0:
  3.   If b is odd: result = (result × a) mod m
  4.   a = (a × a) mod m
  5.   b = b ÷ 2
  6. Return result

Extended Euclidean Algorithm

Finds integers x and y such that ax + by = gcd(a, b):

  1. If b = 0: return (a, 1, 0)
  2. Otherwise: (g, x₁, y₁) = extgcd(b, a mod b)
  3. Return (g, y₁, x₁ - (a ÷ b) × y₁)

Common Patterns