Minimum Players required to win the game | javascript program to find minimum players required to win the game anyhow ; function to calculate ( a ^ b ) % ( 10 ^ 9 + 7 ) . ; function to find the minimum required player ; computing the nenomenator ; computing modulo inverse of denominator ; final result ; Driver code
var mod = 107 ; function power ( a , b ) { var res = 1 ; while ( b != 0 ) { if ( ( b & 1 ) != 0 ) { res *= a ; res = res % mod ; } b = parseInt ( b / 2 ) ; a *= a ; a %= mod ; } return res ; } function minPlayer ( n , k ) { var num = ( ( power ( k , n ) - 1 ) + mod ) % mod ; var den = ( power ( k - 1 , mod - 2 ) + mod ) % mod ; var ans = ( ( ( num * den ) % mod ) * k ) % mod ; return ans ; } var n = 3 , k = 3 ; document . write ( minPlayer ( n , k ) ) ;