text: Power of a prime number ‘ r ’ in n ! | Function to return power of a no . ' r ' in factorial of n ; Keep dividing n by powers of ' r ' and update count ; Driver code
code: function power ( n , r ) { let count = 0 ; for ( let i = r ; ( n / i ) >= 1 ; i = i * r ) count += n / i ; return count ; } let n = 6 , r = 3 ; document . write ( power ( n , r ) ) ;