View Code of Problem 80

#include <stdio.h>
//约瑟夫环问题 f(n,m)=(f(n-1,m)+m)%n; 
//n表示总数,m表示每第几个死; 
int main(){
	int n;
	while(scanf("%d",&n)!=EOF&&n!=0){
		int last=0;
		for(int i=2;i<=n;i++){
			last=(last+3)%i;
		}
		printf("%d\n",last+1);
	}
}

Double click to view unformatted code.


Back to problem 80