Cody

Problem 44067. The last non-zero digit of a factorial

Solution 2598352

Submitted on 22 Jun 2020 by Ramesh Kumar V
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
n = 4; d_correct = 4; assert(isequal(lastNonZeroDigitFactorial(n),d_correct))

a = 24 k = 0 sum = 0 k = 1 m = 4 sum = 4 a = 2 k = 2 m = 4 2 sum = 6 a = 0 b = 2 4 x = 2 4 ind = 1×2 logical array 0 0 ind1 = 1×0 empty double row vector p = logical 1 y = 4

2   Pass
n = 5; d_correct = 2; assert(isequal(lastNonZeroDigitFactorial(n),d_correct))

a = 120 k = 0 sum = 0 k = 1 m = 0 sum = 0 a = 12 k = 2 m = 0 2 sum = 2 a = 1 k = 3 m = 0 2 1 sum = 3 a = 0 b = 1 2 0 x = 1 2 0 ind = 1×3 logical array 0 0 1 ind1 = 3 p = logical 0 y = 2

3   Pass
n = 6; d_correct = 2; assert(isequal(lastNonZeroDigitFactorial(n),d_correct))

a = 720 k = 0 sum = 0 k = 1 m = 0 sum = 0 a = 72 k = 2 m = 0 2 sum = 2 a = 7 k = 3 m = 0 2 7 sum = 9 a = 0 b = 7 2 0 x = 7 2 0 ind = 1×3 logical array 0 0 1 ind1 = 3 p = logical 0 y = 2

4   Pass
n = 7; d_correct = 4; assert(isequal(lastNonZeroDigitFactorial(n),d_correct))

a = 5040 k = 0 sum = 0 k = 1 m = 0 sum = 0 a = 504 k = 2 m = 0 4 sum = 4 a = 50 k = 3 m = 0 4 0 sum = 4 a = 5 k = 4 m = 0 4 0 5 sum = 9 a = 0 b = 5 0 4 0 x = 5 0 4 0 ind = 1×4 logical array 0 1 0 1 ind1 = 2 4 p = logical 0 y = 4

5   Pass
n = 8; d_correct = 2; assert(isequal(lastNonZeroDigitFactorial(n),d_correct))

a = 40320 k = 0 sum = 0 k = 1 m = 0 sum = 0 a = 4032 k = 2 m = 0 2 sum = 2 a = 403 k = 3 m = 0 2 3 sum = 5 a = 40 k = 4 m = 0 2 3 0 sum = 5 a = 4 k = 5 m = 0 2 3 0 4 sum = 9 a = 0 b = 4 0 3 2 0 x = 4 0 3 2 0 ind = 1×5 logical array 0 1 0 0 1 ind1 = 2 5 p = logical 0 y = 2

6   Pass
n = 9; d_correct = 8; assert(isequal(lastNonZeroDigitFactorial(n),d_correct))

a = 362880 k = 0 sum = 0 k = 1 m = 0 sum = 0 a = 36288 k = 2 m = 0 8 sum = 8 a = 3628 k = 3 m = 0 8 8 sum = 16 a = 362 k = 4 m = 0 8 8 2 sum = 18 a = 36 k = 5 m = 0 8 8 2 6 sum = 24 a = 3 k = 6 m = 0 8 8 2 6 3 sum = 27 a = 0 b = 3 6 2 8 8 0 x = 3 6 2 8 8 0 ind = 1×6 logical array 0 0 0 0 0 1 ind1 = 6 p = logical 0 y = 8

7   Pass
n = 10; d_correct = 8; assert(isequal(lastNonZeroDigitFactorial(n),d_correct))

a = 3628800 k = 0 sum = 0 k = 1 m = 0 sum = 0 a = 362880 k = 2 m = 0 0 sum = 0 a = 36288 k = 3 m = 0 0 8 sum = 8 a = 3628 k = 4 m = 0 0 8 8 sum = 16 a = 362 k = 5 m = 0 0 8 8 2 sum = 18 a = 36 k = 6 m = 0 0 8 8 2 6 sum = 24 a = 3 k = 7 m = 0 0 8 8 2 6 3 sum = 27 a = 0 b = 3 6 2 8 8 0 0 x = 3 6 2 8 8 0 0 ind = 1×7 logical array 0 0 0 0 0 1 1 ind1 = 6 7 p = logical 0 y = 8

Community Treasure Hunt

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

Start Hunting!