Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Sorting and Searching

Josephus Problem I

#2162
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

Consider a game where there are nn children (numbered 1,2,…,n1,2,\dots,n) in a circle. During the game, every other child is removed from the circle until there are no children left. In which order will the children be removed?

Input

The only input line has an integer nn.

Output

Print nn integers: the removal order.

Constraints
  • 1≤n≤2⋅1051 \le n \le 2 \cdot 10^5
Sample Test Cases (1)
Example 1ID: sample-1
Input
7
Expected Output
2 4 6 1 5 3 7
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
7
Expected Output
2 4 6 1 5 3 7