Find if nCr is divisible by the given prime | Function to return the highest power of p that divides n ! implementing Legendre Formula ; Return the highest power of p which divides n ! ; Function to return N digits number which is divisible by D ; Find the highest powers of p that divide n ! , r ! and ( n - r ) ! ; If nCr is divisible by p ; Driver code
function getfactor ( n , p ) { let pw = 0 ; while ( n != 0 ) { n = parseInt ( n / p , 10 ) ; pw += n ; } return pw ; } function isDivisible ( n , r , p ) { let x1 = getfactor ( n , p ) ; let x2 = getfactor ( r , p ) ; let x3 = getfactor ( n - r , p ) ; if ( x1 > x2 + x3 ) return 1 ; return 0 ; } let n = 7 , r = 2 , p = 7 ; if ( isDivisible ( n , r , p ) == 1 ) document . write ( " " ) ; else document . write ( " " ) ;