Follows 495.c (Total 40 lines):

/* @JUDGE_ID:4461XX 495 C */
/* A */
#include<stdio.h>
#include<math.h>
#define num 1000000000
long arr[5100][170] ;
void make_arr()
{
	long i , j , where ;
	for( i=2 , where=1 ; i<5100 ; i++ )
		for( j=0 ; j<where ; j++ ){
			arr[i][j] += arr[i-1][j] + arr[i-2][j] ;
			if( arr[i][j] >= num ){
				if( j == where - 1 ) where++ ;
				arr[i][j+1] += arr[i][j] / num ;
				arr[i][j] %= num ;
			}
		}
}
void main( void )
{
	long n , i , j ;
	for( i=0; i<5100 ; i++ )
		for( j=0 ; j<170 ; j++ ) arr[i][j] = 0 ;
	arr[1][0] = 1 ;
	make_arr() ;
	while( scanf( "%ld" , &n ) == 1 ){
		printf( "The Fibonacci number for %ld is " , n ) ;
		for( i=169 ; i>0 ; i-- )
			if( arr[n][i] ) break ;
		printf( "%ld" , arr[n][i--] ) ;
		for( ; i>=0 ; i-- ){
	/*		for( j=100000000 ; j ; j/=10 )
				if( !( arr[n][i] / j ) ) putchar( '0' ) ;
				else break ;*/
			printf( "%09ld" , arr[n][i] ) ;
		}
		putchar( '\n' ) ;
	}
}

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