Given 3 integers N, M and K. The task is to find maximum P such that N * KP <= M .
Input :N = 1, K = 2, M = 5
Input: N = 5, K = 25, M = 100
In this algorithm, simply multiply N with K and update the current value of N with the result and increase variable power (initially 0) by 1.
To achieve this, a recursive function is defined which has 2 base cases.
- If the current value of N is greater than the M. This condition can have two conditions:
- Initially, N is greater than required, therefore, return 0.
- Otherwise, return power – 1.
- If the current value of N is equal to the M then return power.
Recursive condition if current N < M:
Update N as (N * k) and power as current power + 1.
Below is the implementation of the above approach:
- Compute power of power k times % m
- Compute maximum of the function efficiently over all sub-arrays
- Maximum size of sub-array that satisfies the given condition
- Find maximum power of a number that divides a factorial
- Find the sum of power of bit count raised to the power B
- Check if given number is a power of d where d is a power of 2
- Find power of power under mod of a prime
- How to compute mod of a big number?
- Compute (a*b)%c such that (a%c) * (b%c) can be beyond range
- Compute n! under modulo p
- Compute nCr % p | Set 2 (Lucas Theorem)
- Compute sum of digits in all numbers from 1 to n
- Compute nCr % p | Set 3 (Using Fermat Little Theorem)
- Efficient Program to Compute Sum of Series 1/1! + 1/2! + 1/3! + 1/4! + .. + 1/n!
- Compute the parity of a number using XOR and table look-up
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.