View Code of Problem 80

#include<cstdio>
#include<vector>
using namespace std;
int main(){
	int n,i;
	while(scanf("%d",&n)!=EOF&&n!=0){
		int count=n,flag=0;
		vector<int> vt(n+1,1);
		for(i=1;;i++){
			if(i==n+1)	i=1;
			if(vt[i]!=0)	flag++;
			if(flag%3==0&&vt[i]!=0){
				vt[i]=0;
				count--;
			}
			if(count==1)	break;	
		}
		for(i=1;i<=n;i++){
			if(vt[i]!=0)	printf("%d\n",i);
		}		
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 80