方法:循环链表
#include<iostream>
using namespace std;
const int N = 110;
int h, e[N], ne[N], idx;
int n, m;
void init(){
h = -1;
for(int i = n; i >= 1; i --){
e[idx] = i;
ne[idx] = h;
h = idx ++;
}
ne[0] = h;
}
void del(int x){
ne[x] = ne[ne[x]];
}
int main(){
cin >> n >> m;
init();
int cnt = 1, p = h, q = 0;
while(ne[p] != p){
if(cnt == m){
cout << e[p] << ' ';
del(q);
p = ne[q];
cnt = 1;
continue;
}
cnt ++;
q = p;
p = ne[p];
}
cout << e[p];
return 0;
}