-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJosephus Problem II.cpp
More file actions
36 lines (30 loc) · 846 Bytes
/
Josephus Problem II.cpp
File metadata and controls
36 lines (30 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/// Alhamdulillah
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
// template <typename Key, typename Mapped, typename Compare, typename Tag,
// typename Policy>
// class tree;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define ll long long
int main() {
ll n, ans, j;
cin >> n >> j;
ll currentNumber = n;
ll innerStart = 2;
indexed_set st;
for (ll i = 1; i <= n; i++) {
st.insert(i);
}
int ind = j % st.size();
while (!st.empty()) {
int killed = *st.find_by_order(ind);
cout << killed << " ";
st.erase(killed);
if (!st.empty()) ind = ((ind % st.size() + j) % st.size());
}
}