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
< ? php function fact ( $ n ) { $ num = 1 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) $ num = $ num * $ i ; return $ num ; } function Special_Factorial_Number ( $ k ) { for ( $ i = 1 ; $ i <= $ k ; $ i ++ ) { if ( ( fact ( $ i ) % $ k ) == 0 ) { return $ i ; } } } $ k = 16 ; echo Special_Factorial_Number ( $ k ) ; ? >