Given two integers and . The task is to find the maximum value of x, such that, n! % (k^x) = 0.
Input : n = 5, k = 2 Output : 3 Explanation : Given n = 5 and k = 2. So, n! = 120. Now for different values of x: n! % 2^0 = 0, n! % 2^1 = 0, n! % 2^2 = 0, n! % 2^3 = 0, n! % 2^4 = 8, n! % 2^5 = 24, n! % 2^6 = 56, n! % 2^7 = 120. So, the answer should be 3. Input : n = 1000, x = 2 Output : 994
- First take the squareroot of and store it in a variable say, .
- Run the loop from i=2 to m.
- If i = m then copy k to i.
- If k is divisible by i then divide k by i.
- Run a loop to n and add the quotient to a variable say, .
- Store the minimum value of r after every loop.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find maximum among x^(y^2) or y^(x^2) where x and y are given
- Find the maximum possible value of a[i] % a[j] over all pairs of i and j
- Find the maximum value of Y for a given X from given set of lines
- Find the maximum element in the array other than Ai
- Find triplets in an array whose AND is maximum
- Find the maximum number of handshakes
- Find maximum element of each row in a matrix
- Find the Substring with maximum product
- Given count of digits 1, 2, 3, 4, find the maximum sum possible
- Find Sum of pair from two arrays with maximum sum
- Find a pair from the given array with maximum nCr value
- Find pair with maximum GCD in an array
- Find three integers less than or equal to N such that their LCM is maximum
- Find maximum xor of k elements in an array
- Find the node whose sum with X has maximum set bits
- Find the maximum possible value for the given periodic function
- Find the maximum length of the prefix
- Find permutation with maximum remainder Sum
- Find maximum operations to reduce N to 1
- Find a positive number M such that gcd(N^M, N&M) is maximum
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.