Follows 406.c (Total 44 lines):

/* @JUDGE_ID:4461XX 406 C */
/* A */
#include <stdio.h>
#include <string.h>
void main( void )
{
	int prime[170] , j , i=1 , num=2 , yes ;
	char a[10] , *p ;
	prime[0] = 1 ;
	while( i<170 )
	{
		yes = 'n' ;
		for( j=2 ; j<num ; j++ )
			if( num%j==0 ) { yes = 'y' ; break ; }
		if( yes=='y' ) { num++ ; continue ; }
		else { prime[i] = num ; i++ ; }
		num++ ;
	}
	while( gets(a) != NULL )
	{
		int n , c , high , k ;
		p = strtok( a , " " ) ;
		n = atoi( p ) ;
		p = strtok( NULL , " " ) ;
		c = atoi( p ) ;
		printf( "%d %d:" , n , c ) ;
		for( high=0 ; !(prime[high]>n) ; high++ ) { }
		if( high%2==0 )
			if( c*2>=high )
				for( k=0 ; k<high ; k++ )
					printf( " %d" , prime[k] ) ;
			else
				for( k=high/2-c ; k<=high/2+c-1 ; k++ )
					printf( " %d" , prime[k] ) ;
		if( high%2==1 )
			if( c*2-1>=high )
				for( k=0 ; k<high ; k++ )
					printf( " %d" , prime[k] ) ;
			else
				for( k=high/2+1-c ; k<=high/2-c+2*c-1 ; k++ )
					printf( " %d" , prime[k] ) ;
		printf( "\n\n" ) ;
	}
}

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