ArticleslgStudy

computer science

Meissel–Lehmer algorithm

Meissel–Lehmer algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Meissel–Lehmer algorithm rather than just read about it. In short: The Meissel–Lehmer algorithm (after Ernst Meissel and Derrick Henry Lehmer) is an algorithm that computes exact values of the prime-counting function. Description The problem of counting the exact number of primes less than or equal to x, without actually listing them all, dates from Legendre.

Key takeaways

  • Meissel–Lehmer algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Meissel–Lehmer algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Meissel–Lehmer algorithm from memory before moving on to harder problems.

Reference excerpt

The Meissel–Lehmer algorithm (after Ernst Meissel and Derrick Henry Lehmer) is an algorithm that computes exact values of the prime-counting function.

Description The problem of counting the exact number of primes less than or equal to x, without actually listing them all, dates from Legendre. He observed from the Sieve of Eratosthenes that

π ( x ) − π ( x 1 / 2 ) + 1 = ⌊ x ⌋ − ∑ i ⌊ x / p i ⌋ + ∑ i < j ⌊ x / p i p j ⌋ − … {\displaystyle \pi (x)-\pi (x^{1/2})+1=\lfloor x\rfloor -\sum _{i}\lfloor x/p_{i}\rfloor +\sum _{i<j}\lfloor x/p_{i}p_{j}\rfloor -\ldots }

where ⌊x⌋ is the floor function, which denotes the greatest integer less than or equal to x and the pi run over all primes ≤ √x. Since the evaluation of this sum formula becomes more and more complex and confusing for large x, Meissel tried to simplify the counting of the numbers in the Sieve of Eratosthenes. He and Lehmer therefore introduced certain sieve functions, which are detailed below.

Key functions Let p1, p2, …, pn be the first n primes. For a natural number a ≥ 1, define

φ ( x , a ) := | { n ≤ x : p | n ⟹ p > p a } | , {\displaystyle \varphi (x,a):=\left|\left\{n\leq x:p|n\implies p>p_{a}\right\}\right|,}

which counts natural numbers no greater than x with all prime factors greater than pa. Also define for a natural number k,

P k ( x , a ) := | { n ≤ x : n = q 1 q 2 ⋯ q k , with q 1 , … , q k > p a } | , {\displaystyle P_{k}(x,a):=\left|\left\{n\leq x:n=q_{1}q_{2}\cdots q_{k},~{\text{with}}~q_{1},\ldots ,q_{k}>p_{a}\right\}\right|,}

which counts natural numbers no greater than x with exactly k prime factors, all greater than pa. With these, we have

φ ( x , a ) = ∑ k = 0 ∞ P k ( x , a ) , {\displaystyle \varphi (x,a)=\sum _{k=0}^{\infty }P_{k}(x,a),}

where the sum only has finitely many nonzero terms because Pk(x, a) = 0 when pka > x. Using the fact that P0(x, a) = 1 and P1(x, a) = π(x) − a, we get

π ( x ) = φ ( x , a ) + a − 1 − ∑ k = 2 ∞ P k ( x , a ) , {\displaystyle \pi (x)=\varphi (x,a)+a-1-\sum _{k=2}^{\infty }P_{k}(x,a),}

which proves that one may compute π(x) by computing φ(x,a) and Pk(x, a) for k ≥ 2. This is what the Meissel–Lehmer algorithm does.

Formula for Pk(x, a) For k = 2, we get the following formula for Pk(x, a):

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Meissel–Lehmer algorithm

Start with the simplest possible case. Write down what Meissel–Lehmer algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Meissel–Lehmer algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Meissel–Lehmer algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Meissel–Lehmer algorithm

In research
Meissel–Lehmer algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Meissel–Lehmer algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Meissel–Lehmer algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Number theoretic algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Meissel–Lehmer algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Meissel–Lehmer algorithm” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Meissel–Lehmer algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Meissel–Lehmer algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Meissel–Lehmer algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Meissel–Lehmer algorithm in simple terms?

The Meissel–Lehmer algorithm (after Ernst Meissel and Derrick Henry Lehmer) is an algorithm that computes exact values of the prime-counting function. Description The problem of counting the exact number of primes less than or equal to x, without actually listing them all, dates from Legendre.

Why does Meissel–Lehmer algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Meissel–Lehmer algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Meissel–Lehmer algorithm.

Tags

  • Number theoretic algorithms

Keep exploring