fork(3) download
  1. #include <ext/pb_ds/assoc_container.hpp>
  2. #include <ext/pb_ds/tree_policy.hpp>
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace __gnu_pbds;
  6. using namespace std;
  7.  
  8. tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> t;
  9.  
  10. main()
  11. {
  12. ios::sync_with_stdio(0);
  13. cin.tie(0);
  14. int n,k;
  15. cin>>n>>k;
  16. for(int i=0;i<n;i++)
  17. t.insert(i+1);
  18. int cur=0;
  19. while(n)
  20. {
  21. cur=(cur+k-1)%n--;
  22. auto it=t.find_by_order(cur);
  23. cout<<*it<<"\n";
  24. t.erase(it);
  25. }
  26. }
Success #stdin #stdout 0s 3432KB
stdin
5 3
stdout
3
1
5
2
4