Find last two digits of sum of N factorials | Function to find the unit ' s ▁ and ▁ ten ' s place digit ; Let us write for cases when N is smaller than or equal to 10. ; We know following ( 1 ! + 2 ! + 3 ! + 4 ! ... + 10 ! ) % 100 = 13 else ( N >= 10 ) ; Driver code
< ? php function get_last_two_digit ( $ N ) { if ( $ N <= 10 ) { $ ans = 0 ; $ fac = 1 ; for ( $ i = 1 ; $ i <= $ N ; $ i ++ ) { $ fac = $ fac * $ i ; $ ans += $ fac ; } return $ ans % 100 ; } return 13 ; } $ N = 1 ; for ( $ N = 1 ; $ N <= 10 ; $ N ++ ) echo " For ▁ N ▁ = ▁ " . $ N . " ▁ : ▁ " . get_last_two_digit ( $ N ) . " STRNEWLINE " ;