Lucky Number Checker
Sequences
- Lucky numbers come from the Josephus Flavius sieve: write down the odd numbers, then repeatedly delete every k-th survivor, where k is the next surviving number (first 2, then 3, then 7, and so on).
- Sieving up to and beyond 25 leaves 8 lucky numbers at or below it.
- The number 25 survives the sieve at position 8, and the next lucky number is 31.
- Stanislaw Ulam named them in 1956; they mimic the primes surprisingly closely - there is even a lucky-number analogue of the Goldbach conjecture and of twin primes.
Lucky numbers are what survives a sieve with a moving step. Write down the positive integers. Cross out every 2nd number. The first survivor after 1 is 3, so next cross out every 3rd of the numbers that remain. The next survivor is 7, so cross out every 7th remaining number. The numbers never crossed out - 1, 3, 7, 9, 13, 15, 21, 25, 31, ... - are the lucky numbers.
The sieve is called the Josephus Flavius sieve, and it is the primes' playful sibling: where the sieve of Eratosthenes deletes by fixed multiples, this sieve deletes by position, with the step size read off the survivors themselves. The family resemblance runs deep - lucky numbers share several statistical properties with the primes, including a twin-like pairing pattern and a Goldbach-like conjecture.
This lucky number calculator tests membership and generates the list up to any bound. Verified landmarks: 25 is lucky - the 8th lucky number, with the next one after it being 31; 20 is not lucky, with 6 lucky numbers up to 20 and the next at 21; and up to 100 there are exactly 23 lucky numbers, the largest being 99.
Worked examples
Is 25 lucky?
(Test a number · 25)
| is 25 a lucky number? | yes |
| position in the lucky list | 8 |
| lucky numbers up to 25 | 8 |
| next lucky number | 31 |
Is 20 lucky?
(Test a number · 20)
| is 20 a lucky number? | no |
| position in the lucky list | not in the list |
| lucky numbers up to 20 | 6 |
| next lucky number | 21 |
Lucky numbers up to 100
(List up to n · 100)
| lucky numbers up to 100 | 1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43, 49, 51, 63, 67, 69, 73, 75, 79, 87, 93, 99 |
| count up to 100 | 23 |
| largest in the list | 99 |
| smallest in the list | 1 |
The Josephus Flavius sieve
The procedure: list the positive integers. Pass 1 removes every 2nd number (all the evens), leaving the odds. The smallest survivor greater than 1 is 3, so pass 2 removes every 3rd remaining number. The smallest survivor after that round beyond the steps used is 7, so pass 3 removes every 7th remaining number. Each pass's step is the next surviving number, and the passes continue until the step exceeds the length of the list. What remains is the lucky sequence.
The name honours the Josephus problem - the ancient elimination puzzle in which people in a circle are removed at fixed intervals and one asks who survives. The sieve is elimination by position rather than by value, which is what makes it feel different from Eratosthenes: a number's fate depends on how many survivors stand before it, not on its own factors.
- Delete every 2nd, then every 3rd remaining, then every 7th...
- Each step is the next survivor
- Elimination by position, not by value
The list up to 100
Up to 100 there are exactly 23 lucky numbers: 1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43, 49, 51, 63, 67, 69, 73, 75, 79, 87, 93, 99. The smallest is 1 and the largest is 99. The density near 100 - 23 survivors in the first hundred - is comparable to the primes' 25 in the same range, a resemblance that is not coincidence but a theorem-shaped shadow: both sieves thin a list by deleting a shrinking fraction at each pass.
Read the gaps: 2, 4, 2, 4, 2, 6, 4, 6, 2, 4, 6, 6, 2, 12, 4, 2, 4, 2, 4, 8, 6, 6. Mostly small, occasionally a jump - the 12 between 51 and 63 is the largest in this range. Lucky gaps behave statistically like prime gaps, which is one of the observations that made mathematicians take the analogy seriously rather than as a parlour game.
- 23 lucky numbers up to 100
- Smallest 1, largest 99
- Largest gap in range: 12, from 51 to 63
Testing a number: 25 yes, 20 no
The checker reports more than a verdict. For 25: yes, it is the 8th lucky number, there are 8 lucky numbers up to 25, and the next lucky number after it is 31. For 20: no, it is not in the list (it is even, and every even number dies in the first pass), there are 6 lucky numbers up to 20, and the next lucky number is 21. The 'next lucky number' line makes a negative answer useful - it points at the nearest success.
All lucky numbers beyond 1 are odd, trivially: the first pass removes every even number. The interesting tests are the odd failures - 5, 11, 17, 19 die in later passes - and the calculator's position reporting shows exactly where a survivor stands when it does make it.
The odd failures deserve equal attention, because they show the later passes working. Five is odd and survives the first pass, but dies when every 3rd remaining number is struck. Eleven, 17 and 19 also vanish in later rounds - none of them appears in the list up to 100, though each is odd and 19 is even prime. Survival is not about the number's own arithmetic at all: it is about the number's position among the survivors at the moment each pass runs, which is why the sieve's output cannot be predicted by factorisation and must simply be run.
- 25: lucky, position 8, next is 31
- 20: not lucky, 6 up to 20, next is 21
- All lucky numbers after 1 are odd
The prime analogy
Lucky numbers were introduced to the literature by Gardiner, Lazarus, Metropolis and Ulam in 1956, explicitly as a sieve analogue of the primes - and the analogy has proved substantive. The counting function of the lucky numbers tracks n / ln n, the prime number theorem's shape. There are 'twin lucky numbers' - pairs differing by 2, like 13 and 15, or 31 and 33 - with a distribution resembling twin primes. And a Goldbach-style statement (every even number as a sum of two lucky numbers) has been checked computationally over wide ranges.
None of this makes lucky numbers as deep as the primes - the sieve is positional, with no multiplicative structure underneath - but it makes them a laboratory: conjectures too hard for primes can sometimes be tested, and occasionally proved, in the lucky world first. Stanisław Ulam, who named them 'lucky', understood exactly what he was building: a mirror in which prime behaviour could be studied with the arithmetic stripped away.
- Gardiner, Lazarus, Metropolis and Ulam, 1956
- Counting tracks n / ln n, like the primes
- Twin luckies and a Goldbach-like pattern
How the calculator sieves
The implementation runs the positional sieve on a list up to the requested bound, tracking positions rather than values at every pass: remove every k-th entry where k is the next survivor, stop when k exceeds the list length. Test mode then reads off membership, position, the count up to n, and the next lucky number; list mode returns the survivors directly with their count and extremes.
Positional sieving is the whole subtlety: deleting by index while the list shrinks is where off-by-one errors breed, which is why the outputs are anchored on hand-verifiable cases - 23 numbers up to 100 with largest 99, and 25 in position 8. Any sieve implementation that cannot reproduce those two facts is wrong, whatever its internal logic claims.
- Positional sieve; steps read from survivors
- Anchors: 23 up to 100; 25 is 8th
- Off-by-one errors are the classic failure
Using the calculator
Test mode takes any n up to 100,000 and answers membership with position, count and next-lucky information. List mode enumerates the lucky numbers up to n (bounds up to 5,000 keep the output readable) with count, smallest and largest. Both modes use the same sieve, so their answers are consistent by construction.
A good first experiment: list up to 100 and test 25 and 20 against it by eye - 25 sits in the list at position 8, 20 is absent, and the next entry after position 6 (which is 15)... the list itself is the ground truth the checker is summarising.
- Test mode up to 100,000
- List mode with count and extremes
- The list up to 100 is the reference
FAQs
What is a lucky number?
A survivor of the Josephus Flavius sieve: list the positive integers, repeatedly delete every k-th remaining number where k is the next survivor (2, then 3, then 7, ...). The numbers never deleted - 1, 3, 7, 9, 13, ... - are lucky. The sieve is positional - a number's fate depends on how many survivors stand before it, not on its factors.
Is 25 a lucky number?
Yes - it is the 8th lucky number. There are 8 lucky numbers up to 25, and the next lucky number after 25 is 31.
Is 20 a lucky number?
No. Every even number is deleted in the first pass. There are 6 lucky numbers up to 20, and the next lucky number is 21.
How many lucky numbers are there up to 100?
23 - from 1 up to 99. The full list is on this page; the largest gap in the range is 12, between 51 and 63. Their gap pattern - mostly small gaps with occasional jumps - mirrors the primes closely enough that the analogy is a research topic, not just a curiosity.
How are lucky numbers like primes?
They are produced by a sieve, their count up to n tracks n / ln n like the prime number theorem, and they show twin pairs (13 and 15, 31 and 33) and a Goldbach-like pattern. The analogy was the point when Ulam and colleagues introduced them in 1956.
What is the largest lucky number up to 100?
99. The smallest is 1, and there are exactly 23 in the range.