17. Power of k in factorial of n
β GFG solution to find the highest power of k that divides n! using prime factorization and Legendre's formula. π
π§© Problem Description
π Examples
Example 1
Input: n = 7, k = 2
Output: 4
Explanation: 7! = 5040, and 2^4 = 16 is the highest power of 2 that divides 5040.Example 2
Input: n = 10, k = 9
Output: 2
Explanation: 10! = 3628800, and 9Β² = 81 is the highest power of 9 that divides 3628800.π Constraints
β
My Approach
Prime Factorization + Legendre's Formula
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
π§βπ» Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated