#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m;
struct node{
int data;
struct node *nxt;
}*head;
void creatlist(){
head = (struct node*)malloc(sizeof(struct node));
head -> nxt = NULL,head -> data = 1;
struct node *tmphead = head;
for (int i = 2;i <= n;i++){
struct node *curtr;
curtr = (struct node*)malloc(sizeof(struct node));
curtr -> data = i,curtr -> nxt = NULL;
tmphead -> nxt = curtr;
tmphead = curtr;
}
tmphead -> nxt = head;
}
void del(int x){
struct node *tmphead = head;
if (x == head -> data){
while (1){
if (tmphead -> nxt == head){
head = head -> nxt;
tmphead -> nxt = head;
return;
}
tmphead = tmphead -> nxt;
}
return;
}
while (1){
struct node *curtr = tmphead -> nxt;
if (curtr -> data == x){
tmphead -> nxt = curtr -> nxt;
tmphead = tmphead -> nxt;
return;
}
tmphead = tmphead -> nxt;
}
}
int main(){
scanf ("%d%d",&n,&m);
creatlist();
struct node *tmphead = head;
while (n != 1){
int tmpm = m;
while (tmpm > 1){
tmphead = tmphead -> nxt;
tmpm--;
}
del(tmphead -> data);
tmphead = tmphead -> nxt;
n--;
}
printf("%d\n",head -> data);
}
eh
发布时间 2023-09-20 14:30:37作者: 小又又yyyy