Follows 568.c (Total 30 lines):

/* @JUDGE_ID:4461XX 568 C */
/* A */
#include <stdio.h>
void main(void)
{
	int n ,number , i , j , p[4]={ 6 , 2 , 4 , 8 } ;
	long twice ;
	while( scanf( "%d" , &n ) == 1 ){
		number = 1 ;
		twice = 0 ;
		for( j=2 ; j<=n ; j++ ){
			i = j ;
			while( i%2 == 0 ){
				twice++ ;
				i /= 2 ;
			}
			while( i%5 == 0 ){
				twice-- ;
				i /= 5 ;
			}
			number = ( number * ( i % 10 ) ) % 10 ;
		}
		if ( twice == 0 ) number = 1 ;
		else{
			twice %= 4 ;
			number = ( number * p[twice] ) % 10 ;
		}
		printf( "%5d -> %d\n" , n , number ) ;
	}
}

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