Lucky Number Calculator
Find the lucky number at an index from a sieve that repeatedly removes every kth remaining entry.
What it does
Lucky numbers are produced by a sieve similar to the sieve of Eratosthenes, but the rule changes as the process runs. Start with the odd positive integers. The second surviving number is 3, so remove every third remaining number. The next survivor is 7, so remove every seventh remaining number, and so on.
The numbers that survive forever are called lucky. The sequence begins 1, 3, 7, 9, 13, 15, 21 and 25. The name was coined in the twentieth century, and the construction is attributed to work by Stanislaw Ulam and colleagues.
Lucky numbers share surprising statistical properties with the primes. For instance, the number of lucky numbers up to a large limit behaves similarly to the prime counting function, even though the two sequences are defined in completely different ways.
This page runs the sieve up to a bounded limit and returns the lucky number at your chosen index. It also shows the previous lucky number and the gap between them.
The index limit is one thousand, which is well inside the sieve bound so the answer is reliable. Increasing the bound further would slow the page without changing these early terms.
How to use
- Enter an index n from 1 to 1,000.
- Read the lucky number at that index in the main result box.
- Check the previous lucky number beside it.
- Use the gap to see how far apart the survivors are.
- The default index 5 reproduces the worked example.
- Try index 6 to confirm the value 15.
Formula
- list
- The current ordered list of surviving candidates.
- list[k]
- The survivor whose value gives the removal step.
- k
- The index of the current sieve pass.
The sieve starts with 1, 3, 5, 7 and so on. On the first pass every third entry is removed, on the second every seventh, using the next surviving value each time. The process stops once the next step exceeds the length of the list.
Worked example
Example: index 5
The page opens with index 5.
- Start with odd numbers 1, 3, 5, 7, 9, 11, 13, 15 and so on.
- The second survivor is 3, so remove every third entry.
- The list becomes 1, 3, 7, 9, 13, 15, 21 and so on.
- The next survivor is 7, so remove every seventh remaining entry.
- The early survivors are 1, 3, 7, 9, 13 and 15.
- The tool reports lucky 13, previous 9, and gap 4.
Reference table
| n | Lucky(n) | Previous | Gap |
|---|---|---|---|
| 1 | 1 | n/a | n/a |
| 2 | 3 | 1 | 2 |
| 3 | 7 | 3 | 4 |
| 4 | 9 | 7 | 2 |
| 5 | 13 | 9 | 4 |
| 6 | 15 | 13 | 2 |
| 10 | 33 | 31 | 2 |
Limits
- Indices above 1,000 are rejected to keep the sieve quick.
- The sieve uses a fixed upper bound, which is more than enough for these indices.
- The tool returns one term, not the whole surviving list.
- Lucky numbers are not the same as prime numbers, though they behave similarly.
Common mistakes
- Starting the sieve with all integers instead of only odd ones.
- Using a fixed step of two for every pass.
- Using the index rather than the surviving value as the removal step.
- Assuming lucky numbers are a subset of the primes.
- Forgetting that 1 is counted as the first lucky number.
Try it yourself
Quick checks. Answers sit tucked under each question.
What is the fifth lucky number?
13, with 9 before it and a gap of 4.
What is the sixth lucky number?
15.
What is the first lucky number?
1, the first survivor of the sieve.
Questions
How is the sieve different from Eratosthenes?
The removal step changes with each surviving value rather than being the next prime.
Why are they called lucky?
The name reflects the survival process, popularised in work by Ulam and colleagues.
Do they behave like primes?
Their counting function has similar asymptotic behaviour, though the sequences differ.
Is 1 a lucky number?
Yes, it is the first survivor.
Are results exact?
Yes. The sieve uses integer lists only.
What index range is accepted?
One through 1,000.