Number Theory Introduction
Number Theory: Key Concepts and Applications
What is Number Theory?
Number theory is the branch of mathematics primarily concerned with the positive integers (counting numbers: 1, 2, 3, …). It studies their properties: whether they are odd or even, perfect squares or cubes, divisible by a given number, and many other characteristics. The most important objects in number theory are the prime numbers — numbers whose only factors are 1 and themselves. Primes are the building blocks of the subject, analogous to atoms in chemistry. For example, 11, 13, 17, and 19 are primes; 15 and 18 are not (15 = 3×5, 18 = 2×3×3). Some numbers that look prime (like 91 = 7×13 and 323 = 17×19) are not, so determining primality is not always easy.
Key questions in number theory include:
Is a given number prime?
Are numbers composed entirely of ones (like 1111) ever perfect squares?
Problems arising from the calendar (e.g., which years have five Sundays in February?).
Applications to right-angle triangles (Pythagorean triples) and the construction of regular polygons.
Practical applications: card shuffling and cryptography (credit card security), relying on prime number results dating back to the 18th century.
Definition: Number theory studies the positive integers and their properties, with primes playing a central role.
Prime Numbers
Sieve of Eratosthenes
The ancient Greek method for finding primes up to a given limit works by listing all numbers, then crossing out multiples of 2, 3, 5, 7, etc. The numbers not crossed out are primes. For numbers up to 100, the primes are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97.
Why 1 Is Not a Prime
The Fundamental Theorem of Arithmetic states that every positive integer can be expressed uniquely (up to order) as a product of primes. If 1 were considered prime, uniqueness would break (e.g., 6 = 2×3 = 2×3×1 = 2×3×1×1). Therefore, 1 is excluded from the primes.
Infinitude of Primes (Euclid’s Proof)
Euclid's Elements provides a geometric argument that the list of primes never ends. In modern language:
Assume there are only finitely many primes: p1,p2,p3,…,pn. Construct the number
Each prime pi divides the product p1p2⋯pn, so it cannot divide N (since pi would have to divide 1, which is impossible). Therefore N is either prime itself or has a prime factor not among the pi. In either case, a new prime exists, contradicting the assumption. Hence there are infinitely many primes.
Note: N may be prime (e.g., using primes 2,3,5,7 gives N=211, prime) or composite (e.g., using primes up to 13 gives N=30031=59×509, introducing two new primes).
Primes of the Form 4n+1 and 4n+3
Euclid's proof can be adapted to show there are infinitely many primes of the form 4n+3 (e.g., 3, 7, 11). Similarly, there are infinitely many primes of the form 4n+1 (e.g., 5, 13, 17). Numbers of the form 4n+2 are even and cannot be prime except 2 itself.
Dirichlet’s Theorem (1837): For any integers a and b with gcd(a,b)=1, there are infinitely many primes of the form an+b. This includes the cases 4n+1 and 4n+3, and also implies infinitely many primes ending in 1, 3, 7, or 9 (take a=10, b=1,3,7,9).
Mersenne Primes
Numbers of the form 2n−1 are called Mersenne numbers, named after Marin Mersenne. Some Mersenne numbers are prime (e.g., 22−1=3, 23−1=7, 25−1=31, 27−1=127). However, 211−1=2047=23×89 is composite. In general:
If n is composite, then 2n−1 is also composite.
If n is prime, 2n−1 may or may not be prime (no simple rule).
Mersenne primes are important for finding large primes (the 17 most recently discovered primes are Mersenne primes, including 282,589,933−1 with nearly 25 million digits, discovered in December 2018).
Perfect Numbers
A perfect number is a positive integer equal to the sum of its proper divisors (factors excluding itself). Examples:
6: factors 1,2,3 sum to 6.
28: factors 1,2,4,7,14 sum to 28.
496, 8128 are also perfect.
Euclid proved that if 2n−1 is prime (a Mersenne prime), then 2n−1(2n−1) is a perfect number. Over 2000 years later, Euler proved that every even perfect number has this form. The existence of odd perfect numbers remains unknown; if any exist, they must exceed 101500.
Fermat Numbers
Numbers of the form 22n+1 are called Fermat numbers. Fermat conjectured that all such numbers are prime. The first few (3,5,17,257,65537) are indeed prime. But Euler showed that 225+1=4,294,967,297 is divisible by 641 (hence composite). No further Fermat primes have been found; all larger Fermat numbers are known to be composite. Despite this, Fermat primes appear in an unexpected geometric context: the construction of regular polygons.
Construction of Regular Polygons
The ancient Greeks constructed regular polygons (equal sides and angles) using only an unmarked ruler and compasses. They succeeded for triangles (3 sides), squares (4), pentagons (5), hexagons (6), and by doubling sides, polygons with 2n sides. By combining constructions, they also built a 15-sided polygon. However, polygons with 7, 9, 11, 13, 14, 18, or 19 sides were not constructible by those means.
Gauss’s Theorem (age 18): A regular polygon with n sides is constructible with ruler and compass if and only if n is the product of a power of 2 and distinct Fermat primes.
The known Fermat primes are 3, 5, 17, 257, 65537.
Examples of constructible n: 30 (2×3×5), 32 (25), 34 (2×17), 40 (23×5).
Non-constructible n: 35 (5×7, 7 not allowed), 36 (22×32, 3 repeated), 37 (not a Fermat prime), 100 (factor 5 appears twice). Thus a 100-sided regular polygon cannot be constructed with ruler and compasses.
Perfect Squares
Properties of Perfect Squares
The first ten squares: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100.
Observations:
No square ends in 2, 3, 7, or 8.
Sums of consecutive odd numbers give squares: 1=12, 1+3=22, 1+3+5=32, etc. This can be shown geometrically by arranging odd numbers as L-shaped gnomon around a square.
Every square is either a multiple of 4 or one more than a multiple of 4. No square is 4n+2 or 4n+3.
If n is odd, n2≡1(mod8) (one more than a multiple of 8). This can be seen algebraically: n=2k+1⇒n2=4k(k+1)+1, and k(k+1) is even, so n2=8m+1.
Numbers made entirely of ones (11, 111, 1111, …) are all 3mod4, so they cannot be perfect squares.
Pythagorean Triples
A right-angle triangle with integer side lengths satisfies a2+b2=c2 (Pythagorean theorem). Examples: (3,4,5), (5,12,13), (8,15,17). Scaling yields infinitely many, but the primitive triples (with no common factor) are the focus.
Using algebraic arguments, all primitive triples with a odd, b even can be generated by:
where x>y>0, gcd(x,y)=1, and one of x,y is even.
Examples:
x=2,y=1: gives (3,4,5).
x=3,y=2: gives (5,12,13).
x=5,y=2: gives (21,20,29).
These formulas produce all Pythagorean triples. For example, finding all triangles with a side of length 29: either 29 is c (giving x=5,y=2 leading to (21,20,29)) or 29 is a (giving x=15,y=14 leading to (29,420,421)).
Sums of Two Squares
A number can be written as the sum of two squares only if it is of the form 4n or 4n+1 (since squares are 0 or 1mod4). For primes, Fermat’s theorem (proved by Euler) states: every prime p of the form 4n+1 can be written as a sum of two squares in exactly one way. Examples:
5=12+22
13=22+32
17=12+42
29=22+52
41=42+52
Fermat’s Last Theorem
The equation xn+yn=zn has no positive integer solutions for n>2. Fermat claimed a proof (the “margin too small to contain it”), but it remained unproved until 1995 when Andrew Wiles proved the theorem using deep methods. For n=4, Fermat himself gave a proof using the method of infinite descent.
Modular Arithmetic (Clock Arithmetic)
Basics
Modular arithmetic, introduced by Gauss, involves numbers “wrapping around” after reaching a modulus. For a 12-hour clock: 9 + 6 = 3 (mod 12). It is convenient to write 0 for 12, so 8 + 4 = 0 (mod 12).
General definition: a≡b(modn) if n divides a−b (equivalently, a and b leave the same remainder when divided by n).
The same idea applies to days of the week (mod 7). Numbering Sunday=0, Monday=1, …, Saturday=6: Thursday (4) + 4 days = Monday (1 mod 7); Saturday (6) + 3 days = Tuesday (2 mod 7).
Calendar Calculations
John Conway and Lewis Carroll (Charles Dodgson) devised methods to find the day of the week for any date. Carroll's method involves four numbers, added modulo 7:
Century number: Divide the first two digits of the year by 4, subtract remainder from 3, double the result.
Year number: Divide the last two digits of the year by 12; add the quotient, remainder, and the number of times 4 divides the remainder.
Month number: Use a table (e.g., January=0, February=3, March=3, April=6, May=1, June=4, July=6, August=2, September=5, October=0, November=3, December=5).
Day number: Simply the day of the month.
Sum these four numbers, take mod 7 (0=Sunday, 1=Monday, …, 6=Saturday).
Example for 28 September 2020:
Century (20): 20/4 remainder 0 → (3-0)×2 = 6.
Year (20): 20/12 = 1 remainder 8; 4 divides 8 twice; sum = 1+8+2 = 11.
Month (September): 5.
Day: 28.
Total = 6+11+5+28 = 50; 50 mod 7 = 1 → Monday (correct).
For the problem of when February has five Sundays: February must have 29 days (leap year). Using a known starting day (e.g., 1 Jan 2001 was Monday), one finds that 1 Feb 2004 was Sunday, so 2004 works. Because the day cycle repeats every 28 years (due to leap years), the other years in the 21st century are 2032, 2060, 2088.
Fermat’s Little Theorem and Generalizations
Fermat’s Little Theorem
If p is a prime and a is any integer, then ap≡a(modp). Equivalently, if p does not divide a, then ap−1≡1(modp).
Example: 837−8 is divisible by 37. Also 252≡1(mod53).
Proof by counting necklaces: Consider necklaces with p beads and a colors, using at least two colors. The number of strings of p beads with a colors is ap; subtract the a monochromatic strings gives ap−a. When forming necklaces (rotations considered identical), each necklace corresponds to exactly p strings (because p is prime, all rotations are distinct unless the string is monochromatic). Hence the number of distinct necklaces is (ap−a)/p, which must be an integer. Therefore p divides ap−a.
Application: Card Shuffling
A perfect riffle shuffle of 52 cards moves the card from position x to position 2x (mod 53). After n shuffles, a card moves to 2nx (mod 53). The deck returns to original order when 2n≡1(mod53). By Fermat’s little theorem, 252≡1(mod53), and checking smaller divisors of 52 shows that 52 is the smallest such n. Hence 52 shuffles restore a 52‑card deck.
For a 54‑card deck (with two jokers, so 54 cards), we work modulo 55. Since 55=5×11, we need 2n≡1(mod55). Using Fermat’s theorem for 5 and 11: 24≡1(mod5) and 210≡1(mod11). Raising the first to the 5th power gives 220≡1(mod5); squaring the second gives 220≡1(mod11). Thus 220≡1(mod55). No smaller n works, so the answer is 20 shuffles.
Euler’s Theorem (Generalization)
For composite moduli, we use Euler’s totient function ϕ(n): the number of positive integers less than or equal to n that are coprime to n.
For prime p: ϕ(p)=p−1.
For product of distinct primes p and q: ϕ(pq)=(p−1)(q−1).
Example: ϕ(10)=4 (numbers 1,3,7,9); ϕ(12)=4 (1,5,7,11).
Euler’s Theorem: If gcd(a,n)=1, then aϕ(n)≡1(modn).
When n is prime, this reduces to Fermat’s little theorem.
RSA Cryptography
RSA (Rivest, Shamir, Adleman) is a public-key cryptosystem that secures credit card transactions. It relies on the difficulty of factoring large numbers.
Key generation (Bob):
Choose two large primes p and q (e.g., 29 and 37).
Compute N=pq (e.g., 1073).
Compute ϕ(N)=(p−1)(q−1) (e.g., 28×36=1008).
Choose an encryption exponent e such that gcd(e,ϕ(N))=1 (e.g., e=11).
Publish the public key (N,e); keep p, q, ϕ(N) private.
Encryption (Alice):
Convert her message to a number M (with M<N).
Compute ciphertext C=MemodN.
Send C to Bob.
Decryption (Bob):
Find the decryption exponent d such that ed≡1(modϕ(N)) (e.g., 11×275≡1(mod1008), so d=275).
Compute M=CdmodN (by Euler’s theorem, Med≡M(modN)).
The security comes from the fact that multiplying two large primes is easy, but factoring their product back into p and q is computationally infeasible for sufficiently large primes. Thus, given only N and e, an eavesdropper cannot determine d without factoring N.
The entire process relies on:
The one-way nature of multiplication vs. factoring.
Euler’s theorem to guarantee decryption works.
So when you use a credit card online, RSA cryptography, rooted in number theory from the 18th century, protects your data.

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