Find the last digit when factorial of A divides factorial of B | Function which computes the last digit of resultant of B ! / A ! ; if ( A == B ) If A = B , B ! = A ! and B ! / A ! = 1 ; If difference ( B - A ) >= 5 , answer = 0 ; If none of the conditions are true , we iterate from A + 1 to B and multiply them . We are only concerned for the last digit , thus we take modulus of 10 ; driver function
function computeLastDigit ( A , B ) { let variable = 1 ; return 1 ; else if ( ( B - A ) >= 5 ) return 0 ; else { for ( let i = A + 1 ; i <= B ; i ++ ) variable = ( variable * ( i % 10 ) ) % 10 ; return variable % 10 ; } } document . write ( computeLastDigit ( 2632 , 2634 ) ) ;