Modular Arithmetic and Group Theory
Groups, Lagrange’s Theorem, and Applications to Modular Arithmetic
Modular inverses and the greatest common divisor
In modular arithmetic, a residue a has a multiplicative inverse modulo n if there is some residue b such that
The key criterion is
The extended Euclidean algorithm explains why. It finds integers s and t such that
If gcd(a,n)=1, then sa+tn=1. Reducing this equation modulo n gives
so s is an inverse of a modulo n. If the greatest common divisor is not 1, no such inverse can exist.
When n is prime, every nonzero residue modulo n is relatively prime to n and therefore has a multiplicative inverse. For composite n, some nonzero residues may lack inverses.
Groups
A group consists of a set G and a binary operation, often written ⋆, that satisfies four properties.
Closure: For all a,b∈G, the result a⋆b is also in G.
Associativity: For all a,b,c∈G,
(a⋆b)⋆c=a⋆(b⋆c).Identity: There is an element e∈G such that, for every a∈G,
a⋆e=e⋆a=a.Inverses: For each a∈G, there is an element a−1∈G such that
a⋆a−1=a−1⋆a=e.
A group is abelian if its operation is commutative:
for all a,b∈G.
These axioms describe the essential algebraic structure needed for many arguments. A set alone does not determine whether something is a group: the chosen operation matters.
Examples of groups
Integers under addition: The integers Z form an infinite abelian group under addition. The identity is 0, and the inverse of an integer a is −a.
Nonzero rational numbers under multiplication: The set of nonzero rational numbers forms an infinite abelian group under multiplication. The identity is 1, and the inverse of a nonzero rational number is its reciprocal.
Integers under multiplication: The integers do not form a group under multiplication. Although multiplication is closed and has identity 1, most integers do not have integer multiplicative inverses. For instance, the inverse of 2 would be 21, which is not an integer; 0 has no multiplicative inverse at all.
Residues under modular addition
The residues modulo n, denoted Zn, form a finite abelian group under addition modulo n. The identity is 0, and the additive inverse of a residue a is the residue −a.
For example, Z2 consists of the residues 0 and 1. Under addition modulo 2, the sum of two residues is again one of those residues, and every residue has an additive inverse.
Nonzero residues under modular multiplication
For prime p, the nonzero residues modulo p form a group under multiplication modulo p. This follows because:
Multiplication modulo p is closed and associative.
The identity is 1.
Every nonzero residue has an inverse, since it is relatively prime to p.
For composite n, the nonzero residues modulo n do not generally form a group: some nonzero residues are not relatively prime to n and therefore have no multiplicative inverse.
A useful repair is to keep only the residues that are relatively prime to the modulus:
Under multiplication modulo n, this set is a group. Its elements are exactly the residues that have multiplicative inverses.
The order of a finite group
The order of a finite group is its number of elements, written ∣G∣. For example, the group of nonzero residues modulo a prime p has order
because it contains all p residues except 0.
Group size is useful because it restricts the possible sizes of subgroups.
Counting the units modulo a product of two primes
Suppose m=pq, where p and q are distinct primes. The group Zm× consists of residues relatively prime to m. A residue fails this condition if it is divisible by p or by q.
There are pq−1 nonzero residues to consider. Among them:
p−1 are multiples of q.
q−1 are multiples of p.
No nonzero residue less than pq is a multiple of both p and q.
Subtracting the residues that are not relatively prime to pq gives
This count is an important special case of Euler’s totient function, which counts the residues relatively prime to a given modulus. The value (p−1)(q−1) is also central to the RSA cryptosystem.
Subgroups
A subgroup is a subset H of a group G that is itself a group under the same operation. In particular, the operation must remain inside H: if a,b∈H, then a⋆b∈H. Each element of H must also have its inverse in H.
Thus, subgroup closure and inverses must hold within the smaller set, not merely within the larger group.
Example: a subgroup of Z7×
The nonzero residues modulo 7 form the group
The subset
is a subgroup under multiplication modulo 7. Its elements are the successive powers of 2:
Multiplying powers of 2 adds their exponents, so products of elements in H remain in H. The inverse of 2 modulo 7 is 4, and the inverse of 4 is 2; the identity 1 is its own inverse. Therefore, H is a subgroup.
The group has order 6, while H has order 3.
Lagrange’s theorem
Lagrange’s theorem: If G is a finite group and H is a subgroup of G, then ∣H∣ divides ∣G∣.
For example, a group of order 6 cannot have a subgroup of order 4, because 4 does not divide 6. The theorem places strong limits on the possible sizes of subgroups.
Cosets and the proof of Lagrange’s theorem
For an element x∈G, the left coset of H determined by x is
A coset is a translated copy of the subgroup. The proof of Lagrange’s theorem relies on two facts:
Every coset has the same size as H.
Distinct cosets are disjoint, and the cosets together cover all of G.
Each coset has the size of the subgroup
For fixed x, each element h∈H produces an element x⋆h in xH. Suppose two choices h1,h2∈H produce the same result:
Multiplying on the left by x−1 and using associativity gives h1=h2. Thus, different elements of H produce different elements of xH, so
The existence of inverses is essential: it allows cancellation.
Distinct cosets are disjoint
Suppose two cosets intersect, so some element belongs to both. Then for some h1,h2∈H,
Multiplying on the right by h2−1 gives
Because H is closed under inverses and its operation, h1⋆h2−1∈H. Therefore, xj∈xiH, meaning the two cosets are actually the same coset. Consequently, two cosets are either equal or disjoint.
The cosets partition the group
Starting with any element not yet covered, one can choose it as a representative and include its entire coset. Repeating this process eventually covers the finite group. The resulting cosets are disjoint and each has size ∣H∣.
If there are k distinct cosets, then
Therefore, ∣H∣ divides ∣G∣, proving Lagrange’s theorem.
Fermat’s little theorem
Fermat’s little theorem: If p is prime and p∤a, then
ap−1≡1(modp).
An immediate consequence is an explicit formula for the multiplicative inverse of a modulo p:
Thus, when the modulus is prime and a is nonzero modulo p, its inverse is ap−2 modulo p.
Proof using Lagrange’s theorem
Consider the powers of a modulo p. Since a is nonzero modulo p, it belongs to the group Zp×.
There must be a positive integer k such that
To see why, consider successive powers of a modulo p. There are only finitely many possible residues. Eventually two powers must coincide: for some i<j,
Because a has a multiplicative inverse modulo p, the common factor ai can be cancelled, yielding
Let k be the smallest positive exponent for which ak≡1(modp). The powers of a form a subgroup of Zp× with order k. By Lagrange’s theorem,
Therefore, p−1=ck for some positive integer c, and
The theorem follows.
A combinatorial proof of Fermat’s little theorem
Fermat’s little theorem also has a counting interpretation involving strings arranged as necklaces.
For a prime p and a positive integer a, consider strings of length p whose entries are chosen from an alphabet of size a. There are
such strings.
Now join each string’s ends to form a necklace. Rotating a necklace does not create a different necklace. Because p is prime, a necklace has either:
p distinct strings obtained by rotation, or
just one distinct string, if all its entries are identical.
There are a monochromatic strings: one for each possible repeated entry. Every other string belongs to a rotation class of size p. Therefore, the number of non-monochromatic strings, ap−a, is divisible by p:
Equivalently,
If p∤a, then a can be cancelled modulo p, giving
For example, when a=2 and p=5, there are 25 strings of length 5. The two monochromatic strings are all-red and all-blue. The remaining 25−2 strings group into rotation classes of size 5, so 5 divides 25−2.
Euler’s theorem
Fermat’s little theorem applies when the modulus is prime. Euler’s theorem extends the same group-based idea to certain composite moduli.
Euler’s theorem: If m=pq, where p and q are distinct primes, and gcd(a,m)=1, then
a(p−1)(q−1)≡1(modm).
The hypothesis gcd(a,m)=1 ensures that a belongs to the multiplicative group Zm× and therefore has an inverse. The order of this group is
Proof using Lagrange’s theorem
Let k be the smallest positive integer such that
Such a k exists: among sufficiently many powers of a modulo m, two must coincide, and the common power can be cancelled because gcd(a,m)=1 gives a a multiplicative inverse.
The powers of a form a subgroup of Zm× of order k. By Lagrange’s theorem,
Thus, for some integer c,
It follows that
Euler’s theorem and Fermat’s little theorem have the same underlying structure: powers of an invertible element form a subgroup, and Lagrange’s theorem constrains that subgroup’s order. The exponent is the order of the relevant multiplicative group—in the prime case, p−1; in the case m=pq, (p−1)(q−1).
Fields
A field is a set F equipped with addition and multiplication that satisfy the familiar arithmetic rules.
Under addition, F is an abelian group with identity 0.
The nonzero elements of F form an abelian group under multiplication, with identity 1.
Multiplication distributes over addition:
a(b+c)=ab+acfor all a,b,c∈F.
The rational numbers provide a familiar example of a field. Finite fields are particularly useful in applications where values must come from a finite set.
Roots of polynomials over fields
A polynomial of degree d over a field has at most d roots in that field, provided it is not the zero polynomial. For example, a polynomial can be written as
with coefficients pi∈F. A root is a value x∈F for which P(x)=0.
The bound on the number of roots is not specific to real-valued polynomials. It holds over any field, including finite fields. This fact is useful in cryptographic constructions involving polynomials.
Connection to secret sharing
In polynomial-based secret sharing, a secret can be encoded as the constant term of a polynomial over a finite field. Participants receive evaluations of that polynomial at selected points. With enough distinct evaluations, the polynomial can be reconstructed and the secret recovered; with too few, the secret remains concealed under the scheme’s construction.
The bound on the number of roots helps explain why a polynomial of a given degree is constrained by its evaluations and why a threshold number of shares can determine it. Finite fields provide the finite arithmetic setting used for this kind of scheme.
Connection to RSA
Euler’s theorem underlies the exponent relationships used in RSA encryption. The group of invertible residues modulo a product of two distinct primes has order (p−1)(q−1), which makes that quantity central to the RSA construction. The theorem ensures that suitable exponentiation operations can be reversed for residues relatively prime to the modulus.

Ask anything
We've read this whole study set, so questions about it get the best answers.