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:
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.
- Find maximum among x^(y^2) or y^(x^2) where x and y are given
- Find two numbers with given sum and maximum possible LCM
- Find the maximum value of Y for a given X from given set of lines
- Find M such that GCD of M and given number N is maximum
- Find the maximum possible value of a[i] % a[j] over all pairs of i and j
- Given count of digits 1, 2, 3, 4, find the maximum sum possible
- Find permutation with maximum remainder Sum
- Find pair with maximum GCD in an array
- Find the maximum element in the array other than Ai
- Find maximum xor of k elements in an array
- Find a pair from the given array with maximum nCr value
- Find the node whose sum with X has maximum set bits
- Find the maximum possible value for the given periodic function
- Find triplets in an array whose AND is maximum
- Find three integers less than or equal to N such that their LCM is maximum
- Find a number M < N such that difference between their XOR and AND is maximum
- Find maximum operations to reduce N to 1
- Find a positive number M such that gcd(N^M, N&M) is maximum
- Find the maximum number of handshakes
- Find Sum of pair from two arrays with maximum sum
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.