Follows 10036.c (Total 53 lines):

/* @JUDGE_ID:4461XX 10036 C "DP" */
/* A */
#include<stdio.h>
#include<string.h>
#define K 100 

int arr[K] , tmp[K] , n , k ;
void copy( void )
{
	int i ;

	for( i=0 ; i<K ; i++ ) arr[i] = tmp[i] ;
}
void input( void )
{
	int i , j , num , tmp1 , tmp2 ;

	memset( arr , 0 , sizeof( int )*K ) ;
	scanf( "%d" , &num ) ;
	num %= k ;
	if( num<0 ) num += k ;
	arr[num] = 1 ;

	for( i=1 ; i<n ; i++ ){
		scanf( "%d" , &num ) ;
		memset( tmp  , 0 , sizeof( int )*K ) ;
		for( j=0 ; j<k ; j++ )
			if( arr[j]==i ){
				tmp1 = ( j + num ) % k ;
				tmp2 = ( j - num ) % k ;
				if( tmp1<0 ) tmp1 += k ;
				if( tmp2<0 ) tmp2 += k ;
				tmp[tmp1] = tmp[tmp2] = i + 1 ;
			}
		copy() ;
	}
}
int main( void )
{
	int casetime ;

	scanf( "%d" , &casetime ) ;
	for( ; casetime ; casetime-- ){
		scanf( "%d %d" , &n , &k ) ;
		input() ;

		if( arr[0]==n ) puts( "Divisible" ) ;
		else puts( "Not divisible" ) ;
	}

	return 0 ;
}
/* @END_OF_SOURCE_CODE */

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