Follows 10061.c (Total 63 lines):

/* @JUDGE_ID:4461XX 10061 C */
/* A */
#include<limits.h>
#include<stdio.h>
#include<math.h>
struct data{
	int prime ;
	int base ;
	int num ;
}data[140] ;
int zero , digit ;

int Do_base( int base )
{
	int tail=-1 , i ;

	for( i=2 ; base!=1 ; i++ )
		if( !( base%i ) ){
			tail++ ;
			data[tail].prime = i ;
			data[tail].base = data[tail].num = 0 ;
			while( !( base%i ) ){
				data[tail].base++ ;
				base /= i ;
			}
		}

	return tail ;
}
void Do_Run( int num , int base )
{
	int i , j , k , tail , min=INT_MAX ;
	double tmp ;

	tail = Do_base( base ) ;
	for( tmp=0.0,i=2 ; i<=num ; i++ ){
		tmp += log( i )/log( base ) ;

		for( k=i,j=0 ; j<=tail&&k!=1 ; j++ )
			while( !( k%data[j].prime ) ){
				data[j].num++ ;
				k /= data[j].prime ;
			}
	}
	for( i=0 ; i<=tail ; i++ )
		if( data[i].num/data[i].base<min )
			min = data[i].num / data[i].base ;

	digit = (int)tmp + 1 ;
	zero = min ;
}
int main( void )
{
	int num , base ;

	while( scanf( "%d %d" , &num , &base )==2 ){
		Do_Run( num,base ) ;
		printf( "%d %d\n" , zero , digit ) ;
	}

	return 0 ;
}
/* @END_OF_SOURCE_CODE */

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