forked from the-hyp0cr1t3/CC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJosephus Problem II.cpp
39 lines (37 loc) · 1.1 KB
/
Josephus Problem II.cpp
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
37
38
39
/**
🍪 thew6rst
🍪 10.02.2021 13:21:34
**/
#ifdef W
#include "k_II.h"
#else
#include <bits/stdc++.h>
using namespace std;
#endif
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) static_cast<int32_t>(x.size())
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class key, class value = null_type, class cmp = std::less<key>>
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ook order_of_key // count of elements strictly smaller than k
#define fbo find_by_order // iterator to kth element starting from 0
const int64_t DESPACITO = 2e18;
const int INF = 2e9, MOD = 1e9+7;
const int N = 2e5 + 5;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int i, n, k, pos = 0;
cin >> n >> k;
ordered_set<int> os;
for(i = 1; i <= n; i++)
os.insert(i);
do {
pos = (pos + k) % n;
auto it = os.fbo(pos);
cout << *it << " \n"[i == n];
os.erase(it);
} while(--n);
} // ~W