It's time to get excited about numbers!!! Well, we're just dealing with factorials here, but it's still a good reason to get excited. You're given two numbers, n and k. Calculate the highest exponent of k that could appear in n!
For example, for n=5 and k=2, you're looking for the highest exponent of 2 that could appear in 5!, or 120. The highest power of 2 that evenly divides 120 is 3 (2^3 evenly divides 120, while 2^4 does not) so your output for maxexp(5,2)=3.
You can assume that both n and k are both integers greater than 1.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers31
Suggested Problems
-
Get the area codes from a list of phone numbers
1076 Solvers
-
1633 Solvers
-
Getting the indices from a vector
12339 Solvers
-
Create a matrix X, where each column is a shifted copy of the vector v
226 Solvers
-
Numbers spiral diagonals (Part 1)
306 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Please add test cases:
assert(isequal(maxexp(1e9, 2), 999999987))
assert(isequal(maxexp(1e9, 3), 499999993))
The harder test cases were going to be in version 2 of the problem. This was just to get the ball rolling. I see that you went ahead and submitted the problem with your added test cases, which is never a bad thing. Thanks, and I'm glad you liked the problem!