Find the first natural number whose factorial is divisible by x | function for calculating factorial ; function for check Special_Factorial_Number ; call fact function and the Modulo with k and check if condition is TRUE then return i ; taking input
function fact ( n ) { let num = 1 ; for ( let i = 1 ; i <= n ; i ++ ) { num = num * i ; } return num ; } function Special_Factorial_Number ( k ) { for ( let i = 1 ; i <= k ; i ++ ) { if ( fact ( i ) % k == 0 ) { return i ; } } return 0 ; } let k = 16 ; document . write ( Special_Factorial_Number ( k ) ) ;