View Code of Problem 80

//约瑟夫环问题
#include<stdio.h>
int main()
{
    int n,m=3,s=0,i;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)
           return 0;
        for(i=2;i<=n;i++)
        {
            s=(s+m)%i;
        }
        printf("%d\n",s+1);
    }
}

Double click to view unformatted code.


Back to problem 80