#include <stdio.h>
#include <stdlib.h>
#include<malloc.h>
struct node
{
int data;
struct node *next;
};
struct node *h,*t,*p;
int main()
{
int m,n,i;
while(scanf("%d",&m)&&m!=0)
{
h=(struct node *)malloc(sizeof(struct node));
h->next=NULL;
t=h;
for(i=1; i<=m; i++)
{
p=(struct node *)malloc(sizeof(struct node));
p->data=i;
p->next=NULL;
t->next=p;
t=p;
}
t->next=h->next;
n=0;
struct node *q=t;
p=h->next;
int a=1;
while(p)
{
for(i=0; i<4; i++)//说是5,实际上往后查四个人。
{
q=q->next;
p=p->next;
}
if(p->data!=a)
{
q->next=p->next;
p=q->next;//不是排长就将其删除
n++;
}
else
{
n++;//排长自己也要算进去
break;
}
}
printf("%d\n",n);
}
return 0;
}
01-28