Minimum Players required to win the game | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define mod  1000000007 NEW_LINE long long int power ( long long int a , long long int b ) { long long int res = 1 ; while ( b ) { if ( b & 1 ) { res *= a ; res %= mod ; } b /= 2 ; a *= a ; a %= mod ; } return res ; } long long int minPlayer ( long long int n , long long int k ) { long long int num = ( ( power ( k , n ) - 1 ) + mod ) % mod ; long long int den = ( power ( k - 1 , mod - 2 ) + mod ) % mod ; long long int ans = ( ( ( num * den ) % mod ) * k ) % mod ; return ans ; } int main ( ) { long long int n = 3 , k = 3 ; cout << minPlayer ( n , k ) ; return 0 ; }