Search

Search papers and lessons

Primes in Arithmetic Progressions

Level 3 · 12 min read

Dirichlet's theorem says every arithmetic progression whose first term and step share no factor contains infinitely many primes, and the primes spread evenly over the allowed residue classes.

On this page

  • Colour = topic mix
  • Discrete math
  • Calculus
  • ReadReady to readNot yet

TL;DR

Dirichlet's theorem says that if aa and qq have no common factor, the progression a,a+q,a+2q,…a, a + q, a + 2q, \ldots contains infinitely many primes. A stronger form says the primes are shared out evenly among the allowed remainders mod qq. The proof needs tools beyond elementary counting, which is why the result was a landmark when it appeared in 1837.

Builds on: Prime Number Theorem, Euler's Totient Function · Leads to: the Bombieri-Vinogradov theorem, Dirichlet characters

Where it's used

Choosing moduli for fast arithmetic. Some algorithms multiply large polynomials using a modular version of the Fourier transform, and they need a prime pp with p−1p - 1 divisible by a large power of 2. The prime 998244353 is one such prime, and it satisfies 998244353=119×223+1998244353 = 119 \times 2^{23} + 1. Dirichlet's theorem guarantees that such primes exist for every power of 2, which is why the search for them is worth doing.

Searching for a prime in a required class. A program that needs a prime p≡1(modm)p \equiv 1 \pmod{m} can search the progression 1,1+m,1+2m,…1, 1 + m, 1 + 2m, \ldots and expect to find primes after a modest number of tries. The walkthrough below explains why.

Counting primes by type. Analysts of prime tables compare how many primes fall in each residue class. The even split predicted by the theorem is the baseline against which any bias is measured.

How it works

Take the modulus q=4q = 4. The remainders coprime to 4 are 1 and 3, so there are φ(4)=2\varphi(4) = 2 allowed classes. Dirichlet's theorem says the odd primes should split between them, roughly evenly, and that each class contains infinitely many primes.

  1. List the allowed classes. Numbers congruent to 0 or 2 mod 4 are even, so they can hold only the prime 2. The allowed classes are 1 mod 41 \bmod 4 and 3 mod 43 \bmod 4. Check: each of 1 and 3 shares no factor with 4.
  2. List the primes up to 30. They are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, which is 10 primes.
  3. Sort them by remainder mod 4. The primes ≡1(mod4)\equiv 1 \pmod 4 are 5, 13, 17 and 29, which is 4 of them. The primes ≡3(mod4)\equiv 3 \pmod 4 are 3, 7, 11, 19 and 23, which is 5 of them. The prime 2 is the one left over. Check: 4+5+1=104 + 5 + 1 = 10.
  4. Compare with the even split. Among the 9 odd primes up to 30, an even split would give 4.5 to each class. The observed 4 and 5 are close to that.
  5. Go further. Up to 100 the odd primes split 11 to 13. The even split would give 12 and 12. Check: 11 + 13 + 1 = 25, which is π(100)\pi(100).
  6. Read off the rule. Both classes keep receiving primes, and the difference between them stays small compared with the total. Dirichlet's theorem says this does not stop: each allowed class receives infinitely many primes.
204060801000510xcumulative count of primes
  • primes 1 mod 4
  • primes 3 mod 4
Cumulative counts of primes in the two allowed classes mod 4, up to 100. Both curves climb steadily, and they stay close to each other. At x = 100 the counts are 11 and 13.

The math

Definition: Primes in arithmetic progressions

Let q≥1q \geq 1 and let aa satisfy gcd⁡(a,q)=1\gcd(a, q) = 1. Then the progression a,a+q,a+2q,…a, a + q, a + 2q, \ldots contains infinitely many primes. More precisely, let π(x;q,a)\pi(x; q, a) be the number of primes p≤xp \le x with p≡a(modq)p \equiv a \pmod q. Then

π(x;q,a)∼1φ(q)⋅xln⁡x,x→∞.\pi(x; q, a) \sim \frac{1}{\varphi(q)} \cdot \frac{x}{\ln x}, \qquad x \to \infty.

The second statement says the primes are shared out evenly among the φ(q)\varphi(q) allowed classes, which is the sense in which they "spread evenly".

Step 1 in symbols: the allowed classes

The classes a mod qa \bmod q with gcd⁡(a,q)=1\gcd(a, q) = 1 form a group under multiplication, the group of units mod qq. Its size is φ(q)\varphi(q), the totient. For q=4q = 4 the group is {1,3}\{1, 3\}, of size 2. Each allowed class should get about π(x)/φ(q)\pi(x)/\varphi(q) of the primes.

Step 2 in symbols: separating classes with characters

A Dirichlet character χ\chi mod qq is a function on the integers that is periodic mod qq, is zero when gcd⁡(n,q)>1\gcd(n, q) > 1, and is a group homomorphism from the units mod qq into the unit circle of the complex numbers. For q=4q = 4 there are two characters: the trivial character χ0\chi_0, which is 1 on odd numbers, and χ1\chi_1, which is χ1(n)=1\chi_1(n) = 1 when n≡1(mod4)n \equiv 1 \pmod 4 and −1-1 when n≡3(mod4)n \equiv 3 \pmod 4.

For an odd prime pp, the indicator of p≡1(mod4)p \equiv 1 \pmod 4 is

1[p≡1(mod4)]=12(χ0(p)+χ1(p)).\mathbf{1}[p \equiv 1 \pmod 4] = \tfrac{1}{2}\big(\chi_0(p) + \chi_1(p)\big).

Check: if p≡1p \equiv 1, the bracket is 1+1=21 + 1 = 2, and half of that is 1. If p≡3p \equiv 3, the bracket is 1−1=01 - 1 = 0.

In general the same orthogonality of characters gives, for gcd⁡(a,q)=1\gcd(a, q) = 1,

π(x;q,a)=1φ(q)∑χ mod qχ(a)‾∑p≤xχ(p).\pi(x; q, a) = \frac{1}{\varphi(q)} \sum_{\chi \bmod q} \overline{\chi(a)} \sum_{p \le x} \chi(p).

Step 3 in symbols: the trivial character

The trivial character gives ∑p≤xχ0(p)=π(x)\sum_{p \le x} \chi_0(p) = \pi(x) up to the finitely many primes dividing qq. By the Prime Number Theorem, this is about x/ln⁡xx / \ln x. So the trivial character supplies the main term 1φ(q)⋅xln⁡x\frac{1}{\varphi(q)} \cdot \frac{x}{\ln x}.

Step 4 in symbols: the other characters

For a nontrivial character χ\chi, the sum ∑p≤xχ(p)\sum_{p \le x} \chi(p) must grow more slowly than x/ln⁡xx / \ln x. For q=4q = 4, the check at x=100x = 100 is ∑p≤100χ1(p)=11−13=−2\sum_{p \le 100} \chi_1(p) = 11 - 13 = -2, which is tiny beside 25.

The reason is the L-function L(s,χ)=∑n≥1χ(n)/nsL(s, \chi) = \sum_{n \ge 1} \chi(n) / n^{s}, which converges for real s>1s > 1. Writing it as an Euler product over primes, ln⁡L(s,χ)≈∑pχ(p) p−s\ln L(s, \chi) \approx \sum_p \chi(p)\, p^{-s} for ss near 1. The key fact is that L(1,χ)L(1, \chi) is finite and nonzero for every nontrivial χ\chi. For q=4q = 4 this is the Leibniz series 1−13+15−⋯=π/41 - \tfrac13 + \tfrac15 - \cdots = \pi/4.

Step 5 in symbols: infinitely many primes

For the trivial character, L(s,χ0)L(s, \chi_0) is essentially ζ(s)\zeta(s), which diverges as s→1+s \to 1^+. This divergence is the reason there are infinitely many primes at all. For a progression a mod qa \bmod q, the same argument gives

∑p≡a(modq)1p=1φ(q)∑χχ(a)‾∑pχ(p)p.\sum_{p \equiv a \pmod q} \frac{1}{p} = \frac{1}{\varphi(q)} \sum_{\chi} \overline{\chi(a)} \sum_{p} \frac{\chi(p)}{p}.

The trivial character's sum diverges, and the nontrivial sums stay bounded because L(1,χ)≠0L(1, \chi) \neq 0. So the left side diverges, which forces infinitely many primes in the class a mod qa \bmod q.

Worked examples

Example
1. Tiny: the classes mod 3 up to 20

The allowed classes mod 3 are 11 and 22. The primes up to 20 are 2, 3, 5, 7, 11, 13, 17 and 19.

  1. The prime 3 is divisible by 3, so it is in class 00.
  2. The primes ≡1(mod3)\equiv 1 \pmod 3 are 7, 13 and 19, which is 3 primes.
  3. The primes ≡2(mod3)\equiv 2 \pmod 3 are 2, 5, 11 and 17, which is 4 primes.
  4. Check the total: 1+3+4=81 + 3 + 4 = 8, which is π(20)=8\pi(20) = 8.
  5. Interpretation: the two allowed classes share the 7 primes that are not 3 almost evenly, 3 to 4. The even split would be 3.5 each.
Example
2. Standard: the character count at x = 100

Use q=4q = 4 and x=100x = 100. There are π(100)=25\pi(100) = 25 primes, and exactly one of them, 2, is even. So there are 24 odd primes.

  1. Write the indicator of p≡1(mod4)p \equiv 1 \pmod 4 for odd primes as 12(1+χ1(p))\tfrac12(1 + \chi_1(p)).
  2. Add over the 24 odd primes: ∑12(1+χ1(p))=12(24+∑χ1(p))\sum \tfrac12(1 + \chi_1(p)) = \tfrac12\big(24 + \sum \chi_1(p)\big).
  3. Compute ∑p≤100χ1(p)=11−13=−2\sum_{p \le 100} \chi_1(p) = 11 - 13 = -2, since there are 11 primes ≡1\equiv 1 and 13 primes ≡3\equiv 3.
  4. So π(100;4,1)=12(24−2)=11\pi(100; 4, 1) = \tfrac12(24 - 2) = 11, which matches the direct count.
  5. Interpretation: the difference between the two classes is only 2, and the character sum is the thing that controls it. The theorem says this sum is small compared with the count, so the split becomes even in the limit.
Example
3. Realistic: a prime for a fast transform

A transform of length 2232^{23} needs a prime p≡1(mod223)p \equiv 1 \pmod{2^{23}}. The candidates are k⋅223+1k \cdot 2^{23} + 1 for whole numbers kk, and all of them are odd, since 2232^{23} is even. Around N=109N = 10^9, the chance that such a candidate is prime is about 223φ(223)⋅1ln⁡N=2ln⁡N\frac{2^{23}}{\varphi(2^{23})} \cdot \frac{1}{\ln N} = \frac{2}{\ln N}.

  1. ln⁡109≈20.72\ln 10^9 \approx 20.72.
  2. The probability is about 2/20.72≈0.0972 / 20.72 \approx 0.097.
  3. The reciprocal is about 10.4. So roughly one candidate in ten is prime.
  4. Interpretation: a search through this progression should find a prime after about ten tries near 10910^9. Dirichlet's theorem says the search never runs out, and the density estimate says how long it takes.

Try it: about how many candidates should you test near N=1012N = 10^{12}? Answer: ln⁡1012≈27.63\ln 10^{12} \approx 27.63, so the probability is about 2/27.63≈0.0722 / 27.63 \approx 0.072, and the expected number of candidates is about 27.63/2≈1427.63 / 2 \approx 14.

Common mistakes and tradeoffs

It is tempting to think the condition gcd⁡(a,q)=1\gcd(a, q) = 1 can be dropped. In fact the progression 6,15,24,33,…6, 15, 24, 33, \ldots, with q=9q = 9, contains no primes at all. Every term is divisible by 3, and 3 itself is not in the progression. The condition is what rules out such common factors.

It is tempting to think the primes are split exactly evenly at every xx. In fact the split is only asymptotic. Up to 100 the classes mod 4 receive 11 and 13 primes. Small leads of one class over the other, such as this one, are called Chebyshev's bias. The theorem says the split evens out in the limit, although the bias can persist for a long range of xx.

It is tempting to think the theorem tells you where the next prime in a class is. In fact it proves that primes exist in the class and that they are spread evenly. It gives no bound on how far apart they are, which needs a different and harder result.

It is tempting to confuse this result with the theorem that the primes contain arbitrarily long arithmetic progressions, which is the Green–Tao theorem. There the progressions are made of primes; here the primes lie in a progression.

Use the theorem when you need primes in a fixed residue class, for example to choose a modulus or to split a count by class. Do not use it when you need an exact position or an exact count; for that, sieve. Its quantitative form is a statement about the limit, so at small xx the counts can differ noticeably from the even split.

History

Legendre conjectured, from tables of primes, that a progression with no common factor should contain infinitely many primes. Gauss and others studied the question too. The even split is the sharper form that the analytic work later made precise.

Peter Gustav Lejeune Dirichlet proved the statement that bears his name in 1837. His proof introduced characters and the L-functions that carry his name, and it used analysis where earlier number theory had used only algebra. The step that needed the most work was showing that L(1,χ)L(1, \chi) is nonzero for nontrivial characters.

In 1896 Jacques Hadamard and Charles Jean de la Vallée Poussin proved the Prime Number Theorem. De la Vallée Poussin extended the same analytic method to progressions, which gave the full asymptotic form π(x;q,a)∼π(x)/φ(q)\pi(x; q, a) \sim \pi(x)/\varphi(q). That extension is what made the result useful beyond the question of infinitude.

It caught on because it answers a practical question about where primes live, and because its method, through characters and L-functions, became the foundation of analytic number theory.

Recap

  • Dirichlet's theorem: if gcd⁡(a,q)=1\gcd(a, q) = 1, the progression a mod qa \bmod q contains infinitely many primes.
  • The primes are shared evenly among the φ(q)\varphi(q) allowed classes, asymptotically.
  • Characters separate the classes, and the trivial character gives the main term from the Prime Number Theorem.
  • The nontrivial characters contribute little because L(1,χ)≠0L(1, \chi) \neq 0, which is the hard step.
  • Read next: Dirichlet Character for the characters themselves, and Bombieri–Vinogradov for a result that averages the progression counts over many moduli.

Check yourself

QuestionState Dirichlet's theorem in words, including the condition on aa and qq.Show answer

If aa and qq share no common factor, the arithmetic progression a,a+q,a+2q,…a, a + q, a + 2q, \ldots contains infinitely many primes. The condition is needed: when aa and qq share a factor, every term shares that factor too, so there are at most finitely many primes in the progression.

QuestionCount the primes up to 30 that are ≡1(mod4)\equiv 1 \pmod 4, and the primes up to 30 that are ≡3(mod4)\equiv 3 \pmod 4.Show answer

The primes up to 30 are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29. Those ≡1(mod4)\equiv 1 \pmod 4 are 5, 13, 17 and 29, which is 4 primes. Those ≡3(mod4)\equiv 3 \pmod 4 are 3, 7, 11, 19 and 23, which is 5 primes. The prime 2 is in neither class.

QuestionWhy does the trivial character produce the main term in the count of primes in a class, while the nontrivial characters do not?Show answer

The trivial character is 1 on every number coprime to qq, so its sum over primes is the full prime count π(x)\pi(x), which is about x/ln⁡xx / \ln x. The nontrivial characters take values +1+1 and −1-1 (or complex values of modulus 1) in a pattern that cancels over primes. Their sums are much smaller because the corresponding L-function is finite and nonzero at s=1s = 1.

QuestionYou need a prime p≡1(modm)p \equiv 1 \pmod{m} with m=220m = 2^{20} near N=109N = 10^{9}. About how many candidates of the form km+1k m + 1 should you test before finding one?Show answer

The density for candidates coprime to mm is about mφ(m)⋅1ln⁡N\frac{m}{\varphi(m)} \cdot \frac{1}{\ln N}. Here m/φ(m)=2m / \varphi(m) = 2, and ln⁡109≈20.72\ln 10^9 \approx 20.72, so the chance of a prime is about 2/20.72≈0.0972 / 20.72 \approx 0.097. The expected number of candidates is about 10.4, so roughly ten.

Sources