Follows 305.c (Total 48 lines):

/* @JUDGE_ID:4461XX 305 C */
/* A */
#include <stdio.h>
typedef struct jose{
	int next ;
}JOSE ;
JOSE a[30] ;
void list( int n )
{
	int i ;
	for( i=0 ; i<n-1 ; i++ )
		a[i].next = i+1 ;
	a[n-1].next = 0 ;
}
void main( void )
{
	int k ;
	long ans[14] ;
	for( k=1 ; k<14 ; k++ ){
		long i , j , m , unkilled , killed=0 , yes=0 , cnt=0 , pre=0 ;
		for( i=k+1 ; ; i++ , cnt=0 , killed=0 , pre=0 ){
			if( yes==1 ) break ;
			list( 2*k ) ;
			unkilled = 2*k ;
			while( yes != 1 ){
				m = i % unkilled ;
				if( i%unkilled == 0 ) m = unkilled ;
				for( j=1 ; j<m ; j++ ){
					pre = cnt ;
					cnt = a[cnt].next ;
				}
				if( cnt>=k ){
					a[pre].next = a[cnt].next ;
					cnt = a[cnt].next ;
					killed++ ;
					unkilled-- ;
					if( killed == k )	yes = 1 ;
				}
				else break ;
			}
		}
		ans[k] = i - 1 ;
	}
	while( scanf( "%d" , &k ) == 1 ){
		if( k == 0 ) break ;
		printf( "%ld\n" , ans[k] ) ;
	}
}

Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com