The Lucky Survivor

HardAcc. 71.4%
+45 XP 25

Iterative Elimination

Lucky numbers are generated by a sieve:

  1. Start with [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15...].
  2. Every 2nd number is removed $ o$ [1, 3, 5, 7, 9, 11, 13, 15...].
  3. The next surviving number is 3. Every 3rd number is removed $ o$ [1, 3, 7, 9, 13, 15...].
  4. The next survivor is 7. Every 7th number is removed... and so on.

The Assignment

Your function receives a parameter limit.

  1. Use a loop to simulate the repeated elimination process on a range from 1 to limit.
  2. Print all surviving "Lucky Numbers" up to the limit.

01EXAMPLE 1

Inputlimit = 15
Output1 3 7 13

Explanation: Survivors of the iterative sieve.

Constraints

  • Print each result on a new line.
  • Use loops to perform the slicing.
MathLoops
JavaScript
Loading...
2 Hidden

Input Arguments

limit15

Expected Output

1
3
7
13

Click RUN to test your solution