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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Compute power of power k times % m
- Check if given number is a power of d where d is a power of 2
- Find the maximum sum (a+b) for a given input integer N satisfying the given condition
- Find power of power under mod of a prime
- Larger of a^b or b^a (a raised to power b or b raised to power a)
- Find the sum of power of bit count raised to the power B
- Maximum size of sub-array that satisfies the given condition
- Compute maximum of the function efficiently over all sub-arrays
- Smallest index in the given array that satisfies the given condition
- Check if given Binary string follows then given condition or not
- Count of sub-sequences which satisfy the given condition
- Divide an array into K subarray with the given condition
- Check if elements of an array can be arranged satisfying the given condition
- Pairs from an array that satisfy the given condition
- Find the final X and Y when they are Altering under given condition
- Count triplet pairs (A, B, C) of points in 2-D space that satisfy the given condition
- Count all possible N digit numbers that satisfy the given condition
- Check whether two strings are equivalent or not according to given condition
- Find the lexicographically smallest string which satisfies the given condition
- Find permutation of first N natural numbers that satisfies the given condition
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.