#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
}*head, *p, *t, *q;
struct node *creat(int n)
{
int i;
p = (struct node *) malloc (sizeof(struct node));
p -> next = NULL;
p -> data = 1;
t = p;
head = p;
for(i = 2; i <= n; i++)
{
p = (struct node *) malloc (sizeof(struct node));
p -> data = i;
p -> next = NULL;
t -> next = p;
t = p;
}
t -> next = head;
return head;
}
void show(struct node *head)
{
int num = 1, count = 0;
q = head;
while(1)
{
num++;
p = q -> next;
if(num % 5 == 0)
{
q -> next = p -> next;
count++;
if(p -> data == 1)
{
printf("%d\n", count);
break;
}
}
else
q = p;
}
}
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
if(n == 0)
break;
else
{
head = creat(n);
show(head);
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
}*head, *p, *t, *q;
struct node *creat(int n)
{
int i;
p = (struct node *) malloc (sizeof(struct node));
p -> next = NULL;
p -> data = 1;
t = p;
head = p;
for(i = 2; i <= n; i++)
{
p = (struct node *) malloc (sizeof(struct node));
p -> data = i;
p -> next = NULL;
t -> next = p;
t = p;
}
t -> next = head;
return head;
}
void show(struct node *head)
{
int num = 1, count = 0;
q = head;
while(1)
{
num++;
p = q -> next;
if(num % 5 == 0)
{
q -> next = p -> next;
count++;
if(p -> data == 1)
{
printf("%d\n", count);
break;
}
}
else
q = p;
}
}
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
if(n == 0)
break;
else
{
head = creat(n);
show(head);
}
}
return 0;
}