Problem 50811. Compute the nth term from the Sieve of Flavius Josephus
To apply the Sieve of Eratosthenes, start with the natural numbers (skipping 1), keep the first number (i.e., 2), and delete all multiples (4, 6, 8, 10, etc.). Then repeat: keep the first remaining number (3) and delete all multiples (9, 15, 21, etc.). The remaining numbers are the primes.
To apply the Sieve of Flavius Josephus, start with the natural numbers. On the kth step, remove every
st term remaining after the
st step. So, on the first step, remove every second number (2, 4, 6, 8, etc.) to leave 1, 3, 5, 7, 9, 11, 13, 15, 17…On the second step, remove every third number (5, 11, 17, etc.) to leave 1, 3, 7, 9, 13, 15, 19,…
Write a function to compute the nth term in the sequence remaining after the Sieve of Flavius Josephus is applied.
Solution Stats
Problem Comments
-
1 Comment
Nikolaos Nikolaou
on 17 Mar 2024
Making me thing that i can get away with brute force was vicious at the very least :D
Solution Comments
Show commentsGroup

Easy Sequences Volume V: Fibonacci Obsession
- 10 Problems
- 1 Finishers
- Cricket - Sort Batters by Distance Run
- Cricket - Average Partnership Contribution
- Cricket - How Much More to Beat Bradman?
- Cricket - Career Batting Statistics
- Cricket - Career Bowling Statistics
- Cricket - Represent Average in "Dulkars" and "Ses"
- Cricket - Peak Batting Average
- Cricket - Report the Result (Part I: Limited Overs)
- Cricket - Most Frequent Bowler-Batter Wicket Combinations
- Cricket - You Miss, I Hit (Rank Bowlers by Proportion of Bowled and LBW Wickets)
- Cricket - Report the Result (Part II: Test Matches)
- Cricket - Is It LBW?
Problem Recent Solvers15
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!