Follows 10220.c (Total 41 lines):

/* @JUDGE_ID:4461XX 10220 C "Big Number" */
/* A */
#include<stdio.h>
#include<string.h>
#define MAX 1000
#define MAX_1000 428

int sum[MAX+1] ;

void MakeTable( void )
{
	int tmp[MAX_1000] , i , j , k ; /* 999999 */
	
	memset( tmp , 0 , sizeof( int )*MAX_1000 ) ;
	tmp[0] = 1 ;
	sum[0] = 1 ;

	for( i=1 ; i<=MAX ; ++i ){
		for( j=0 ; j<MAX_1000 ; ++j ) tmp[j] *= i ; /*multiply*/
		for( j=0 ; j<MAX_1000-1 ; ++j )
			if( tmp[j]>=1000000 ){
				tmp[j+1] += tmp[j]/1000000 ;
				tmp[j] %= 1000000 ;
			}

		for( j=0,sum[i]=0 ; j<MAX_1000 ; ++j ) /*count sum*/
			for( k=1 ; k<1000000 ; k*=10 ) sum[i] += ( tmp[j]/k )%10 ;

	}
}
int main( void )
{
	int n ;

	MakeTable() ;
	
	while( scanf( "%d" , &n )==1 )
		printf( "%d\n" , sum[n] ) ;

	return 0 ;
}

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