1. Home
  2. Explore
  3. Mathematics
  4. Modular Arithmetic and Group Theory

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

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 aaa has a multiplicative inverse modulo nnn if there is some residue bbb such that

ab≡1(modn).ab \equiv 1 \pmod n.ab≡1(modn).

The key criterion is

a has a multiplicative inverse modulo n⟺gcd⁡(a,n)=1.a \text{ has a multiplicative inverse modulo } n \quad\Longleftrightarrow\quad \gcd(a,n)=1.a has a multiplicative inverse modulo n⟺gcd(a,n)=1.

The extended Euclidean algorithm explains why. It finds integers sss and ttt such that

sa+tn=gcd⁡(a,n).sa+tn=\gcd(a,n).sa+tn=gcd(a,n).

If gcd⁡(a,n)=1\gcd(a,n)=1gcd(a,n)=1, then sa+tn=1sa+tn=1sa+tn=1. Reducing this equation modulo nnn gives

sa≡1(modn),sa\equiv 1\pmod n,sa≡1(modn),

so sss is an inverse of aaa modulo nnn. If the greatest common divisor is not 111, no such inverse can exist.

When nnn is prime, every nonzero residue modulo nnn is relatively prime to nnn and therefore has a multiplicative inverse. For composite nnn, some nonzero residues may lack inverses.


Groups

A group consists of a set GGG and a binary operation, often written ⋆\star⋆, that satisfies four properties.

  1. Closure: For all a,b∈Ga,b\in Ga,b∈G, the result a⋆ba\star ba⋆b is also in GGG.

  2. Associativity: For all a,b,c∈Ga,b,c\in Ga,b,c∈G,

    (a⋆b)⋆c=a⋆(b⋆c).(a\star b)\star c=a\star(b\star c).(a⋆b)⋆c=a⋆(b⋆c).
  3. Identity: There is an element e∈Ge\in Ge∈G such that, for every a∈Ga\in Ga∈G,

    a⋆e=e⋆a=a.a\star e=e\star a=a.a⋆e=e⋆a=a.
  4. Inverses: For each a∈Ga\in Ga∈G, there is an element a−1∈Ga^{-1}\in Ga−1∈G such that

    a⋆a−1=a−1⋆a=e.a\star a^{-1}=a^{-1}\star a=e.a⋆a−1=a−1⋆a=e.

A group is abelian if its operation is commutative:

a⋆b=b⋆aa\star b=b\star aa⋆b=b⋆a

for all a,b∈Ga,b\in Ga,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\mathbb ZZ form an infinite abelian group under addition. The identity is 000, and the inverse of an integer aaa is −a-a−a.

  • Nonzero rational numbers under multiplication: The set of nonzero rational numbers forms an infinite abelian group under multiplication. The identity is 111, 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 111, most integers do not have integer multiplicative inverses. For instance, the inverse of 222 would be 12\frac1221​, which is not an integer; 000 has no multiplicative inverse at all.

Residues under modular addition

The residues modulo nnn, denoted Zn\mathbb Z_nZn​, form a finite abelian group under addition modulo nnn. The identity is 000, and the additive inverse of a residue aaa is the residue −a-a−a.

For example, Z2\mathbb Z_2Z2​ consists of the residues 000 and 111. Under addition modulo 222, 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 ppp, the nonzero residues modulo ppp form a group under multiplication modulo ppp. This follows because:

  • Multiplication modulo ppp is closed and associative.

  • The identity is 111.

  • Every nonzero residue has an inverse, since it is relatively prime to ppp.

For composite nnn, the nonzero residues modulo nnn do not generally form a group: some nonzero residues are not relatively prime to nnn and therefore have no multiplicative inverse.

A useful repair is to keep only the residues that are relatively prime to the modulus:

Zn×={a∈Zn:gcd⁡(a,n)=1}.\mathbb Z_n^\times = \{a\in\mathbb Z_n:\gcd(a,n)=1\}.Zn×​={a∈Zn​:gcd(a,n)=1}.

Under multiplication modulo nnn, 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∣|G|∣G∣. For example, the group of nonzero residues modulo a prime ppp has order

∣Zp×∣=p−1,|\mathbb Z_p^\times|=p-1,∣Zp×​∣=p−1,

because it contains all ppp residues except 000.

Group size is useful because it restricts the possible sizes of subgroups.

Counting the units modulo a product of two primes

Suppose m=pqm=pqm=pq, where ppp and qqq are distinct primes. The group Zm×\mathbb Z_m^\timesZm×​ consists of residues relatively prime to mmm. A residue fails this condition if it is divisible by ppp or by qqq.

There are pq−1pq-1pq−1 nonzero residues to consider. Among them:

  • p−1p-1p−1 are multiples of qqq.

  • q−1q-1q−1 are multiples of ppp.

  • No nonzero residue less than pqpqpq is a multiple of both ppp and qqq.

Subtracting the residues that are not relatively prime to pqpqpq gives

∣Zpq×∣=(pq−1)−(p−1)−(q−1)=(p−1)(q−1).|\mathbb Z_{pq}^\times| =(pq-1)-(p-1)-(q-1) =(p-1)(q-1).∣Zpq×​∣=(pq−1)−(p−1)−(q−1)=(p−1)(q−1).

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)(p-1)(q-1)(p−1)(q−1) is also central to the RSA cryptosystem.


Subgroups

A subgroup is a subset HHH of a group GGG that is itself a group under the same operation. In particular, the operation must remain inside HHH: if a,b∈Ha,b\in Ha,b∈H, then a⋆b∈Ha\star b\in Ha⋆b∈H. Each element of HHH must also have its inverse in HHH.

Thus, subgroup closure and inverses must hold within the smaller set, not merely within the larger group.

Example: a subgroup of Z7×\mathbb Z_7^\timesZ7×​

The nonzero residues modulo 777 form the group

Z7×={1,2,3,4,5,6}.\mathbb Z_7^\times=\{1,2,3,4,5,6\}.Z7×​={1,2,3,4,5,6}.

The subset

H={1,2,4}H=\{1,2,4\}H={1,2,4}

is a subgroup under multiplication modulo 777. Its elements are the successive powers of 222:

20≡1,21≡2,22≡4,23≡1(mod7).2^0\equiv1,\qquad 2^1\equiv2,\qquad 2^2\equiv4,\qquad 2^3\equiv1\pmod 7.20≡1,21≡2,22≡4,23≡1(mod7).

Multiplying powers of 222 adds their exponents, so products of elements in HHH remain in HHH. The inverse of 222 modulo 777 is 444, and the inverse of 444 is 222; the identity 111 is its own inverse. Therefore, HHH is a subgroup.

The group has order 666, while HHH has order 333.


Lagrange’s theorem

Lagrange’s theorem: If GGG is a finite group and HHH is a subgroup of GGG, then ∣H∣|H|∣H∣ divides ∣G∣|G|∣G∣.

For example, a group of order 666 cannot have a subgroup of order 444, because 444 does not divide 666. The theorem places strong limits on the possible sizes of subgroups.

Cosets and the proof of Lagrange’s theorem

For an element x∈Gx\in Gx∈G, the left coset of HHH determined by xxx is

xH={x⋆h:h∈H}.xH=\{x\star h:h\in H\}.xH={x⋆h:h∈H}.

A coset is a translated copy of the subgroup. The proof of Lagrange’s theorem relies on two facts:

  1. Every coset has the same size as HHH.

  2. Distinct cosets are disjoint, and the cosets together cover all of GGG.

Each coset has the size of the subgroup

For fixed xxx, each element h∈Hh\in Hh∈H produces an element x⋆hx\star hx⋆h in xHxHxH. Suppose two choices h1,h2∈Hh_1,h_2\in Hh1​,h2​∈H produce the same result:

x⋆h1=x⋆h2.x\star h_1=x\star h_2.x⋆h1​=x⋆h2​.

Multiplying on the left by x−1x^{-1}x−1 and using associativity gives h1=h2h_1=h_2h1​=h2​. Thus, different elements of HHH produce different elements of xHxHxH, so

∣xH∣=∣H∣.|xH|=|H|.∣xH∣=∣H∣.

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∈Hh_1,h_2\in Hh1​,h2​∈H,

xi⋆h1=xj⋆h2.x_i\star h_1=x_j\star h_2.xi​⋆h1​=xj​⋆h2​.

Multiplying on the right by h2−1h_2^{-1}h2−1​ gives

xj=xi⋆h1⋆h2−1.x_j=x_i\star h_1\star h_2^{-1}.xj​=xi​⋆h1​⋆h2−1​.

Because HHH is closed under inverses and its operation, h1⋆h2−1∈Hh_1\star h_2^{-1}\in Hh1​⋆h2−1​∈H. Therefore, xj∈xiHx_j\in x_iHxj​∈xi​H, 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∣|H|∣H∣.

If there are kkk distinct cosets, then

∣G∣=k∣H∣.|G|=k|H|.∣G∣=k∣H∣.

Therefore, ∣H∣|H|∣H∣ divides ∣G∣|G|∣G∣, proving Lagrange’s theorem.


Fermat’s little theorem

Fermat’s little theorem: If ppp is prime and p∤ap\nmid ap∤a, then

ap−1≡1(modp).a^{p-1}\equiv1\pmod p.ap−1≡1(modp).

An immediate consequence is an explicit formula for the multiplicative inverse of aaa modulo ppp:

ap−2⋅a≡1(modp).a^{p-2}\cdot a\equiv1\pmod p.ap−2⋅a≡1(modp).

Thus, when the modulus is prime and aaa is nonzero modulo ppp, its inverse is ap−2a^{p-2}ap−2 modulo ppp.

Proof using Lagrange’s theorem

Consider the powers of aaa modulo ppp. Since aaa is nonzero modulo ppp, it belongs to the group Zp×\mathbb Z_p^\timesZp×​.

There must be a positive integer kkk such that

ak≡1(modp).a^k\equiv1\pmod p.ak≡1(modp).

To see why, consider successive powers of aaa modulo ppp. There are only finitely many possible residues. Eventually two powers must coincide: for some i<ji<ji<j,

ai≡aj(modp).a^i\equiv a^j\pmod p.ai≡aj(modp).

Because aaa has a multiplicative inverse modulo ppp, the common factor aia^iai can be cancelled, yielding

aj−i≡1(modp).a^{j-i}\equiv1\pmod p.aj−i≡1(modp).

Let kkk be the smallest positive exponent for which ak≡1(modp)a^k\equiv1\pmod pak≡1(modp). The powers of aaa form a subgroup of Zp×\mathbb Z_p^\timesZp×​ with order kkk. By Lagrange’s theorem,

k∣p−1.k\mid p-1.k∣p−1.

Therefore, p−1=ckp-1=ckp−1=ck for some positive integer ccc, and

ap−1=ack=(ak)c≡1c≡1(modp).a^{p-1} =a^{ck} =(a^k)^c \equiv1^c \equiv1\pmod p.ap−1=ack=(ak)c≡1c≡1(modp).

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 ppp and a positive integer aaa, consider strings of length ppp whose entries are chosen from an alphabet of size aaa. There are

apa^pap

such strings.

Now join each string’s ends to form a necklace. Rotating a necklace does not create a different necklace. Because ppp is prime, a necklace has either:

  • ppp distinct strings obtained by rotation, or

  • just one distinct string, if all its entries are identical.

There are aaa monochromatic strings: one for each possible repeated entry. Every other string belongs to a rotation class of size ppp. Therefore, the number of non-monochromatic strings, ap−aa^p-aap−a, is divisible by ppp:

p∣ap−a.p\mid a^p-a.p∣ap−a.

Equivalently,

ap≡a(modp).a^p\equiv a\pmod p.ap≡a(modp).

If p∤ap\nmid ap∤a, then aaa can be cancelled modulo ppp, giving

ap−1≡1(modp).a^{p-1}\equiv1\pmod p.ap−1≡1(modp).

For example, when a=2a=2a=2 and p=5p=5p=5, there are 252^525 strings of length 555. The two monochromatic strings are all-red and all-blue. The remaining 25−22^5-225−2 strings group into rotation classes of size 555, so 555 divides 25−22^5-225−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=pqm=pqm=pq, where ppp and qqq are distinct primes, and gcd⁡(a,m)=1\gcd(a,m)=1gcd(a,m)=1, then

a(p−1)(q−1)≡1(modm).a^{(p-1)(q-1)}\equiv1\pmod m.a(p−1)(q−1)≡1(modm).

The hypothesis gcd⁡(a,m)=1\gcd(a,m)=1gcd(a,m)=1 ensures that aaa belongs to the multiplicative group Zm×\mathbb Z_m^\timesZm×​ and therefore has an inverse. The order of this group is

∣Zm×∣=(p−1)(q−1).|\mathbb Z_m^\times|=(p-1)(q-1).∣Zm×​∣=(p−1)(q−1).

Proof using Lagrange’s theorem

Let kkk be the smallest positive integer such that

ak≡1(modm).a^k\equiv1\pmod m.ak≡1(modm).

Such a kkk exists: among sufficiently many powers of aaa modulo mmm, two must coincide, and the common power can be cancelled because gcd⁡(a,m)=1\gcd(a,m)=1gcd(a,m)=1 gives aaa a multiplicative inverse.

The powers of aaa form a subgroup of Zm×\mathbb Z_m^\timesZm×​ of order kkk. By Lagrange’s theorem,

k∣(p−1)(q−1).k\mid (p-1)(q-1).k∣(p−1)(q−1).

Thus, for some integer ccc,

(p−1)(q−1)=ck.(p-1)(q-1)=ck.(p−1)(q−1)=ck.

It follows that

a(p−1)(q−1)=(ak)c≡1(modm).a^{(p-1)(q-1)} =(a^k)^c \equiv1\pmod m.a(p−1)(q−1)=(ak)c≡1(modm).

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−1p-1p−1; in the case m=pqm=pqm=pq, (p−1)(q−1)(p-1)(q-1)(p−1)(q−1).


Fields

A field is a set FFF equipped with addition and multiplication that satisfy the familiar arithmetic rules.

  • Under addition, FFF is an abelian group with identity 000.

  • The nonzero elements of FFF form an abelian group under multiplication, with identity 111.

  • Multiplication distributes over addition:

    a(b+c)=ab+aca(b+c)=ab+aca(b+c)=ab+ac

    for all a,b,c∈Fa,b,c\in Fa,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 ddd over a field has at most ddd roots in that field, provided it is not the zero polynomial. For example, a polynomial can be written as

P(x)=p0+p1x+⋯+pdxd,P(x)=p_0+p_1x+\cdots+p_dx^d,P(x)=p0​+p1​x+⋯+pd​xd,

with coefficients pi∈Fp_i\in Fpi​∈F. A root is a value x∈Fx\in Fx∈F for which P(x)=0P(x)=0P(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)(p-1)(q-1)(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.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent