View Code of Problem 80

#include<bits/stdc++.h>
using namespace std;
//约瑟夫环 f(m,n)=(f(n-1,m)+m)%n 
int main() {
	int n,f;
	while(cin>>n) {
		if(n==0) break;
		f=0;
		for(int i=2; i<=n; i++) {
			f=(f+3)%i;
		}
		cout<<f+1<<endl;
	} 
}

Double click to view unformatted code.


Back to problem 80