View Code of Problem 80

# include<stdio.h>
int main(){
	int n,i;
	scanf("%d",&n);
	int A[n+1]; 
	if(n!=0){
		for( i=1;i<=n;i++){
			A[i]=i;
		}
		
	} 
	int len=n;
	int count=1;
	for(i=1;i<=n&&len!=1;i=(++i)%(n+1)){
		if(i==0){
			i=1;
		}
		if(A[i]!=0&&count!=3){
			count++;
		}
		else{
			if(A[i]!=0&&count==3){
				A[i]=0;
				count=1;
				len--;
			}	
		}
		
	}
	for(i=1;i<=n;i++){
		if(A[i]!=0){
			printf("%d",i);
			break;
			
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 80