Minimum Players required to win the game | Python 3 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
mod = 1000000007 NEW_LINE def power ( a , b ) : NEW_LINE INDENT res = 1 NEW_LINE while ( b ) : NEW_LINE INDENT if ( b & 1 ) : NEW_LINE INDENT res *= a NEW_LINE res %= mod NEW_LINE DEDENT b //= 2 NEW_LINE a *= a NEW_LINE a %= mod NEW_LINE DEDENT return res NEW_LINE DEDENT def minPlayer ( n , k ) : NEW_LINE INDENT num = ( ( power ( k , n ) - 1 ) + mod ) % mod NEW_LINE den = ( power ( k - 1 , mod - 2 ) + mod ) % mod NEW_LINE ans = ( ( ( num * den ) % mod ) * k ) % mod NEW_LINE return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n , k = 3 , 3 NEW_LINE print ( minPlayer ( n , k ) ) NEW_LINE DEDENT