0

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
40
41
42
43
44
#include<stdio.h>
#include<malloc.h>
typedef struct node{
int math;
int data;
struct node *next;
}node, *Linklist;
void Initlist(Linklist *L){
(*L)=(Linklist)malloc(sizeof(node));
(*L)->next=(*L);
}
void created(Linklist *L, int n){
node *s,*r;
r=*L;
for (int i=1;i<=n;i++){
s=(Linklist)malloc(sizeof(node));
scanf("%d",&s->data);
s->math = i;
r->next=s;
r=s;
}
r->next=(*L)->next;
}
void circle(Linklist L,int n,int m){
Linklist p;
p=L;
while(n--){
for(int j=0;j<m-1;j++){
p = p->next;
}
printf("%d ",p->next->math);
m = p->next->data;
p->next=p->next->next;
}
}
int main() {
int n,m;
Linklist L;
Initlist(&L);
scanf("%d %d",&n, &m);
created(&L,n);
circle(L,n,m);
return 0;
}