#include <iostream> #include <cstdlib> #include <cstring> using namespace std; const int maxn=1e5+10; typedef struct Queue { int front,rear; int num[maxn]; } Queue; void InitQueue(Queue &q) { q.front=0; q.rear=0; return ; } bool QueueEmpty(Queue &q) { if((q.rear)%maxn==(q.front)%maxn) return true; else return false; } bool QueueFull(Queue &q) { if(q.front%maxn==(q.rear+1)%maxn) return true; else return false; } void QueuePush(Queue &q,int x) { q.num[q.rear]=x; q.rear=(q.rear+1)%maxn; return ; } void QueuePop(Queue &q) { q.front=(q.front+1)%maxn; return ; } int QueueTop(Queue &q) { return q.num[q.front]; } typedef struct node { int no; node *next; }node; void init(node *&head,node *&last,int no) { head=(node *)malloc(sizeof(node)); head->next=head; head->no=no; last=head; return ; } void insert(node *&last,int no) { node *tmp=(node *)malloc(sizeof(node)); tmp->next=last->next; last->next=tmp; tmp->no=no; last=tmp; return ; } void solve(node *&head,node *&last,Queue &q,int m) { InitQueue(q); node *cur=head,*pre=last; int k=0; while(cur!=pre) { k++; if(k==m) { if(!QueueFull(q)) QueuePush(q,cur->no); m=cur->no;k=0; node *tmp=cur; pre->next=cur->next; cur=cur->next; free(tmp); } else { pre=cur; cur=cur->next; } } QueuePush(q,cur->no); return ; } int main() { node *head,*last; int n,m; Queue q; while(cin>>n>>m) { for(int i=1; i<=n; i++) { i!=1?insert(last,i):init(head,last,i); } solve(head,last,q,m); for(int i=1;i<=n;i++) { i==n?cout<<QueueTop(q)<<endl:cout<<QueueTop(q)<<" "; if(!QueueEmpty(q)) QueuePop(q); } } return 0; }