1. Home
  2. Explore
  3. Mathematics
  4. Prime Density and the Chinese Remainder Theorem

Study methods

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

Prime Density and the Chinese Remainder Theorem

Prime Distribution and Cryptography

Prime counts and density

The prime-counting function π(x)\pi(x)π(x) counts the prime numbers less than or equal to xxx. For example, π(10)=4\pi(10)=4π(10)=4, because the primes up to 101010 are 2,3,5,2,3,5,2,3,5, and 777.

The proportion of integers up to xxx that are prime is π(x)x\frac{\pi(x)}{x}xπ(x)​. This proportion is called the density of primes up to xxx. A useful estimate is that this density is on the order of 1log⁡2x\frac{1}{\log_2 x}log2​x1​, where log⁡2\log_2log2​ is the logarithm to base 222. Equivalently, the number of primes up to xxx is on the order of xlog⁡2x\frac{x}{\log_2 x}log2​xx​.

The logarithmic estimate was conjectured by Gauss after he examined tables of primes. The elementary argument developed here gives constant-factor bounds of the general form

xlog⁡2x ≲ π(x) ≲ 5xlog⁡2x,\frac{x}{\log_2 x}\ \lesssim\ \pi(x)\ \lesssim\ \frac{5x}{\log_2 x},log2​xx​ ≲ π(x) ≲ log2​x5x​,

with small-range and additive-error details depending on the precise version of the bounds. In particular, the estimates show that primes become less frequent as numbers grow, but remain numerous enough for many computational applications.

The key conclusion is that π(x)\pi(x)π(x) grows roughly like xlog⁡2x\frac{x}{\log_2 x}log2​xx​, rather than like xxx.


Three lemmas used to estimate the number of primes

Lemma 1: A lower bound on the central binomial coefficient

For a positive integer nnn,

(2nn)≥4n2n+1.\binom{2n}{n}\geq \frac{4^n}{2n+1}.(n2n​)≥2n+14n​.

The binomial theorem gives

∑i=02n(2ni)=22n=4n.\sum_{i=0}^{2n}\binom{2n}{i}=2^{2n}=4^n.∑i=02n​(i2n​)=22n=4n.

Among the 2n+12n+12n+1 terms in this sum, the central term (2nn)\binom{2n}{n}(n2n​) is the largest. The largest term in a sum is at least the average of its terms, so

(2nn)≥4n2n+1.\binom{2n}{n}\geq \frac{4^n}{2n+1}.(n2n​)≥2n+14n​.

Thus, the central binomial coefficient is large: it is at least the average size of all the binomial coefficients in its row.

Lemma 2: Prime-power factors of the central binomial coefficient

For every prime ppp, the full power of ppp dividing (2nn)\binom{2n}{n}(n2n​) is at most 2n2n2n. In other words, if pvpp^{v_p}pvp​ is the largest power of ppp dividing this binomial coefficient, then

pvp≤2n.p^{v_p}\leq 2n.pvp​≤2n.

The binomial coefficient can be written as

(2nn)=(n+1)(n+2)⋯(2n)1⋅2⋯n.\binom{2n}{n}=\frac{(n+1)(n+2)\cdots(2n)}{1\cdot2\cdots n}.(n2n​)=1⋅2⋯n(n+1)(n+2)⋯(2n)​.

This quotient compares factors from the interval above nnn with factors from 111 through nnn. Prime powers appearing in the denominator are largely matched by corresponding divisibility among the numerator factors. The prime-power contribution that remains for any one prime is bounded by the size of the numerator range, namely 2n2n2n.

Consequently, although (2nn)\binom{2n}{n}(n2n​) itself can be very large, no single prime contributes a power larger than 2n2n2n to its factorization.

Lemma 3: The product of primes up to nnn

For every positive integer nnn,

∏p≤np primep≤4n.\prod_{\substack{p\leq n\\p\text{ prime}}}p\leq 4^n.∏p≤np prime​​p≤4n.

This is proved by induction, separating the odd and even cases.

Odd case

Suppose n=2m+1n=2m+1n=2m+1. Split the primes up to 2m+12m+12m+1 into two groups:

  • Primes p≤m+1p\leq m+1p≤m+1.

  • Primes m+1<p≤2m+1m+1<p\leq 2m+1m+1<p≤2m+1.

By the induction hypothesis, the product of the first group is at most 4m+14^{m+1}4m+1.

Each prime in the second group divides (2m+1m)\binom{2m+1}{m}(m2m+1​). Indeed,

(2m+1m)=(m+2)(m+3)⋯(2m+1)1⋅2⋯m,\binom{2m+1}{m}=\frac{(m+2)(m+3)\cdots(2m+1)}{1\cdot2\cdots m},(m2m+1​)=1⋅2⋯m(m+2)(m+3)⋯(2m+1)​,

and a prime greater than m+1m+1m+1 appears among the numerator factors but not among the denominator factors. Since the primes in this group are distinct, their product is at most the binomial coefficient.

The two central terms in the binomial expansion of (1+1)2m+1(1+1)^{2m+1}(1+1)2m+1 are equal and largest. Their sum is at most the sum of all the terms, which is 22m+12^{2m+1}22m+1. Therefore,

(2m+1m)≤22m=4m.\binom{2m+1}{m}\leq 2^{2m}=4^m.(m2m+1​)≤22m=4m.

Combining the two groups gives

∏p≤2m+1p primep≤4m+1⋅4m=42m+1.\prod_{\substack{p\leq 2m+1\\p\text{ prime}}}p \leq 4^{m+1}\cdot4^m =4^{2m+1}.∏p≤2m+1p prime​​p≤4m+1⋅4m=42m+1.

Even case

If n=2mn=2mn=2m, then 2m2m2m is not prime, so the product of primes up to 2m2m2m is the same as the product of primes up to 2m−12m-12m−1. Applying the odd case gives

∏p≤2mp primep≤42m−1<42m.\prod_{\substack{p\leq 2m\\p\text{ prime}}}p \leq 4^{2m-1} <4^{2m}.∏p≤2mp prime​​p≤42m−1<42m.

The odd and even cases complete the induction.


Estimating the number of primes up to xxx

Upper bound

Consider the primes in the interval (x,x](\sqrt{x},x](x​,x]. Their number is

π(x)−π(x).\pi(x)-\pi(\sqrt{x}).π(x)−π(x​).

Each such prime is greater than x\sqrt{x}x​. Therefore, their product is at least

(x)π(x)−π(x).(\sqrt{x})^{\pi(x)-\pi(\sqrt{x})}.(x​)π(x)−π(x​).

By Lemma 3, the product of all primes up to xxx is at most 4x4^x4x. The product of just the primes in (x,x](\sqrt{x},x](x​,x] cannot be larger, so

(x)π(x)−π(x)≤4x.(\sqrt{x})^{\pi(x)-\pi(\sqrt{x})}\leq 4^x.(x​)π(x)−π(x​)≤4x.

Taking base-222 logarithms yields

(π(x)−π(x))log⁡2x2≤2x,\bigl(\pi(x)-\pi(\sqrt{x})\bigr)\frac{\log_2 x}{2}\leq 2x,(π(x)−π(x​))2log2​x​≤2x,

and hence

π(x)−π(x)≤4xlog⁡2x.\pi(x)-\pi(\sqrt{x})\leq \frac{4x}{\log_2 x}.π(x)−π(x​)≤log2​x4x​.

There are at most x\sqrt{x}x​ integers up to x\sqrt{x}x​, so π(x)≤x\pi(\sqrt{x})\leq\sqrt{x}π(x​)≤x​. Thus,

π(x)≤4xlog⁡2x+x.\pi(x)\leq \frac{4x}{\log_2 x}+\sqrt{x}.π(x)≤log2​x4x​+x​.

For the relevant range, x≤xlog⁡2x\sqrt{x}\leq \frac{x}{\log_2 x}x​≤log2​xx​, giving the convenient estimate

π(x)≤5xlog⁡2x.\pi(x)\leq \frac{5x}{\log_2 x}.π(x)≤log2​x5x​.

This improves on the simple observation π(x)≤x\pi(x)\leq xπ(x)≤x: the number of primes is substantially smaller than the number of integers up to xxx.

Lower bound

Every prime factor of (2nn)\binom{2n}{n}(n2n​) is at most 2n2n2n. By Lemma 2, the contribution from each distinct prime factor is at most 2n2n2n, and there are at most π(2n)\pi(2n)π(2n) such primes. Therefore,

(2nn)≤(2n)π(2n).\binom{2n}{n}\leq (2n)^{\pi(2n)}.(n2n​)≤(2n)π(2n).

Lemma 1 provides a lower bound for the same binomial coefficient:

4n2n+1≤(2nn).\frac{4^n}{2n+1}\leq \binom{2n}{n}.2n+14n​≤(n2n​).

Combining the bounds and taking base-222 logarithms gives

2n−log⁡2(2n+1)≤π(2n)log⁡2(2n).2n-\log_2(2n+1)\leq \pi(2n)\log_2(2n).2n−log2​(2n+1)≤π(2n)log2​(2n).

Thus,

π(2n)≥2n−log⁡2(2n+1)log⁡2(2n).\pi(2n)\geq \frac{2n-\log_2(2n+1)}{\log_2(2n)}.π(2n)≥log2​(2n)2n−log2​(2n+1)​.

This is approximately 2nlog⁡2(2n)\frac{2n}{\log_2(2n)}log2​(2n)2n​, apart from a relatively small correction. For general xxx, an even integer can be chosen close to xxx, producing a corresponding lower estimate of order xlog⁡2x\frac{x}{\log_2 x}log2​xx​, with a small additive error.

Together, the upper and lower estimates show that

π(x)=Θ ⁣(xlog⁡2x),\pi(x)=\Theta\!\left(\frac{x}{\log_2 x}\right),π(x)=Θ(log2​xx​),

meaning that the number of primes is bounded above and below by constant multiples of xlog⁡2x\frac{x}{\log_2 x}log2​xx​ for sufficiently large xxx.


Prime-containing intervals

The estimates on π(x)\pi(x)π(x) can be used to study intervals containing primes. The number of primes in (x,6x](x,6x](x,6x] is

π(6x)−π(x).\pi(6x)-\pi(x).π(6x)−π(x).

Lower-bounding the first term and upper-bounding the second can show that this difference is positive for sufficiently large xxx. The coarse constant-factor bounds require care with logarithms and small values of x‘;theydonotbythemselvesestablishtheclaimforeveryx`; they do not by themselves establish the claim for everyx‘;theydonotbythemselvesestablishtheclaimforeveryx$ without additional checking.

A stronger classical result is Bertrand’s postulate, proved by Chebyshev: for every integer n>1n>1n>1, there is a prime between nnn and 2n2n2n. This is a much sharper guarantee than merely finding a prime within a constant multiple of nnn.

There cannot be a fixed number ccc such that every interval (x,x+c](x,x+c](x,x+c] contains a prime. Prime gaps can be arbitrarily long, so some intervals of any fixed length contain no prime.

A famous unproved conjecture, often called Legendre’s conjecture, states that there is a prime between every pair of consecutive squares:

n2and(n+1)2.n^2 \quad\text{and}\quad (n+1)^2.n2and(n+1)2.

The interval’s length is 2n+12n+12n+1, which is small compared with its starting point n2n^2n2. Bertrand’s postulate does not establish this conjecture: an interval from n2n^2n2 to 2n22n^22n2 is far wider than the interval between consecutive squares.


Chinese remainder theorem

For a system of congruences in one variable, such as

x≡ai(modni),x\equiv a_i\pmod{n_i},x≡ai​(modni​),

if the moduli nin_ini​ are pairwise coprime, the Chinese remainder theorem guarantees a solution that is unique modulo the product of the moduli. This result is useful in number theory and computation because it allows a problem modulo a large number to be represented through several congruences modulo smaller, coprime numbers.


Cryptography: communicating over an insecure channel

Cryptography concerns methods for communicating messages so that intended recipients can understand them while adversaries observing the communication cannot. A channel may be a physical object, a wire, a wireless transmission, or a storage device. It is considered insecure if an adversary can observe the information sent through it.

Two important communication concerns are:

  • Error correction: recovering or detecting information when a channel or storage medium introduces errors.

  • Security: preventing an adversary from understanding or exploiting the message.

Error-correcting codes address the first concern. They are essential because real devices and communication channels can introduce errors. Algebraic methods are often used to detect or correct corrupted data. Cryptography addresses the second concern.

Participants and message representation

A typical model uses three participants:

  • Alice, who sends a message.

  • Bob, who receives it.

  • Eve, an adversary who can observe the channel.

The message, called the plaintext and denoted MMM, can be represented as a string of bits. Text, numbers, punctuation, and other data can be encoded as binary strings.

An encryption algorithm uses a secret SSS and plaintext MMM to produce a ciphertext CCC:

C=E(S,M).C=E(S,M).C=E(S,M).

Bob applies a corresponding decryption algorithm using the secret to recover the message:

M=D(S,C).M=D(S,C).M=D(S,C).

Decryption must recover the intended plaintext uniquely and correctly. If the recovered message could be ambiguous or incorrect, the system would not be dependable.

Shared secrets

A basic way for Alice and Bob to keep a conversation private is for them to share a secret before communicating. They use that secret to encrypt and decrypt messages, while Eve observes only the ciphertext.

This approach makes the security of the system depend on several factors:

  • How difficult it is for Eve to discover the secret.

  • How the encryption algorithm uses the secret.

  • Whether patterns in the plaintext leak information about the secret.

Substitution ciphers

A substitution cipher replaces each letter with another letter according to a secret permutation of the alphabet. For example, a cyclic shift may map AAA to BBB, BBB to CCC, and so on, with ZZZ mapped back to AAA. This particular shift is a form of the Caesar cipher.

Encryption applies the permutation π\piπ to the message:

C=π(M).C=\pi(M).C=π(M).

Decryption applies the inverse permutation:

M=π−1(C).M=\pi^{-1}(C).M=π−1(C).

If the secret is a general permutation of the 262626 letters, there are 26!26!26! possible keys. This may seem like a large search space, but a large key space alone does not guarantee practical security.

Frequency analysis

Natural languages are not arbitrary strings. Letters occur at unequal rates: for example, some letters are common in English, while others are rare. A monoalphabetic substitution preserves these frequency patterns, even though it changes which symbols represent which letters.

An adversary can use frequency analysis by examining ciphertext and comparing its letter frequencies with those typical of the language. Repeated words, common letter combinations, and context can provide further clues. With enough meaningful ciphertext, Eve may infer much of the substitution and use linguistic patterns to complete the recovery.

A cipher can have many possible keys and still be insecure if its ciphertext preserves recognizable structure from the plaintext.

For this reason, simple substitution ciphers are not practically secure. Modern cryptography uses more sophisticated mathematical methods, including ideas from number theory and algebra. Conversely, a long secret key is not by itself a proof of security: the encryption method must also resist attacks that exploit patterns or other information in the messages.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent