The Lucky Survivor
HardAcc. 71.4%
+45 XP 25
Iterative Elimination
Lucky numbers are generated by a sieve:
- Start with [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15...].
- Every 2nd number is removed $ o$ [1, 3, 5, 7, 9, 11, 13, 15...].
- The next surviving number is 3. Every 3rd number is removed $ o$ [1, 3, 7, 9, 13, 15...].
- The next survivor is 7. Every 7th number is removed... and so on.
The Assignment
Your function receives a parameter limit.
- Use a loop to simulate the repeated elimination process on a range from 1 to
limit. - Print all surviving "Lucky Numbers" up to the
limit.
01EXAMPLE 1
Input
limit = 15Output
1
3
7
13Explanation: Survivors of the iterative sieve.
Constraints
- Print each result on a new line.
- Use loops to perform the slicing.
MathLoops
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
limit15
Expected Output
1 3 7 13
Click RUN to test your solution