Cody

Problem 44747. Exponents in Factorials

Solution 3325768

Submitted on 22 Oct 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
assert(isequal(maxexp(5,2),3))

ans = 3

2   Pass
assert(isequal(maxexp(9,3),4))

ans = 4

3   Fail
assert(isequal(maxexp(10,14),1))

ans = 0

Assertion failed.

4   Pass
q=arrayfun(@(x) maxexp(x,13),2:12); assert(all(q==0))

ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0

5   Fail
assert(isequal(maxexp(67,2),64))

Error using factor (line 26) When n is single or double, its maximum allowed value is FLINTMAX. Error in maxexp (line 2) z=factor(prod(1:n)); Error in Test5 (line 1) assert(isequal(maxexp(67,2),64))

6   Fail
assert(isequal(maxexp(10,4),4))

ans = 0

Assertion failed.

7   Fail
s1=maxexp(100,3); s2=maxexp(200,5); assert(isequal(maxexp(s2,s1)-maxexp(s1,s2),maxexp(100,13)+1))

Error using factor (line 26) When n is single or double, its maximum allowed value is FLINTMAX. Error in maxexp (line 2) z=factor(prod(1:n)); Error in Test7 (line 1) s1=maxexp(100,3);

8   Fail
v=zeros(1,99); for a=2:100 v(a-1)=maxexp(100,a); end assert(isequal(sum(v==1),10)) assert(isequal(sum(find(v==2)),496)) assert(isequal(sum(v),1299)) assert(isequal(max(v)-min(v),96))

Error using factor (line 26) When n is single or double, its maximum allowed value is FLINTMAX. Error in maxexp (line 2) z=factor(prod(1:n)); Error in Test8 (line 3) v(a-1)=maxexp(100,a);

Suggested Problems

More from this Author80

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!