- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Minimum Players required to win the game in C++

## Problem statement

Given N questions and K options for each question, where 1 <= N <= 1000000000 and 1 <= K <= 1000000000. The task is to determine sum of total number of player who has attempted ith question for all 1 <= i <= k to win the game anyhow. You have to minimize the sum of total number of player and output it modulo 109+7.

Please note that any wrong answer leads to elimination of the player

## Example

If N = 5 and K = 2 then answer is 62.

### Algorithm

- To solve N
^{th}question K players are needed. - To solve (N-1)
^{th}question K2 players are needed. - Similarly moving onwards, to solve 1
^{st}question KN players are needed. - So, our problem reduces to finding the sum of GP terms K + K
^{2 }+ … + KN which is equal to: K(K^{n}-1) / K -1

## Example

#include <iostream> #include <cmath> #define MOD 1000000007 using namespace std; long long int power(long long a, long long b) { long long res = 1; while (b) { if (b & 1) { res = res * a; res = res % MOD; } b = b / 2; a = a * a; a = a % MOD; } return res; } long long getMinPlayer(long long n, long long k) { long long num = ((power(k, n) - 1) + MOD) % MOD; long long den = (power(k - 1, MOD - 2) + MOD) % MOD; long long ans = (((num * den) % MOD) * k) % MOD; return ans; } int main() { long long n = 5, k = 2; cout << "Minimum pairs = " << getMinPlayer(n, k) << endl; return 0; }

## Output

When you compile and execute above program. It generates following output −

Minimum pairs = 62

- Related Questions & Answers
- C++ program to count how many ways two players win or make draw in dice throwing game
- Program to find number of expected moves required to win Lotus and Caterpillar game in Python
- Program to check whether first player can win a game where players can form string char by char in C++
- Program to find out if we win in a game in Python
- Program to check whether Amal can win stone game or not in Python
- Program to find number of possible moves to start the game to win by the starter in Python
- Program to find number of moves to win deleting repeated integer game in Python
- Program to check whether first player win in candy remove game or not in Python?
- Minimum rotations required to get the same string in C++
- Program to check person 1 can win the candy game by taking maximum score or not in Python
- Minimum positive integer required to split the array equally in C++
- Minimum Initial Energy Required To Cross Street in C++
- Minimum operations required to remove an array in C++
- Minimum operations required to make all the array elements equal in C++
- Automate Mobile Testing to Win The Race

Advertisements