Given N questions and K options for each question, where and . The task is to determine sum of total number of player who has attempted ith question for all to win the game anyhow. You have to minimize the sum of total number of player and output it modulo 109+7.
Note: Any wrong answer leads to elimination of the player.
Input: N = 3, K = 3 Output: 39 Input: N = 5, K = 2 Output: 62
- To solve Nth question K players are needed.
- To solve (N-1)th question K2 players are needed.
- Similarly moving onwards, To solve 1st question KN players are needed.
So, our problem reduces to finding the sum of GP terms K + K2 + … + KN which is equal to .
Now we can use Fermat’s Little Theorem to get the required answer modulo with 109+7.
Below is the implementation of above approach:
Time Complexity: O(log(n))
- Minimum possible final health of the last monster in a game
- Minimum number of palindromes required to express N as a sum | Set 1
- Minimum number of palindromes required to express N as a sum | Set 2
- Minimum operations required to change the array such that |arr[i] - M| <= 1
- Minimum number of operations required to reduce N to 1
- Minimum number of changes required to make the given array an AP
- Minimum number of given operation required to convert n to m
- Minimum number operations required to convert n to m | Set-2
- Minimum number of integers required to fill the NxM grid
- Minimum number of mails required to distribute all the questions
- Minimum number of bottles required to fill K glasses
- Minimum time required to complete a work by N persons together
- Minimum time required to fill a cistern using N pipes
- Minimum number of given moves required to make N divisible by 25
- Minimum deletions required to make GCD of the array equal to 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.