#include
#include
#define N 3
int numberOFf(int m);
int main()
{
int m;
puts("How much people are there in this queue: ");
scanf("%d", &m);
printf("The last people remaining is number %d!\n", numberOff(m));
getch();
return 0;
}
int numberOff(int m)
{
int i = 0, p, tmp;
while(++i <= m)
{
p = i * N;
while (p > m)
{
p = p - m + (p - m - 1) / (N - 1);
}
tmp = p;
}
return tmp;
}