kyu_5.number_of_trailing_zeros_of_n package
Submodules
kyu_5.number_of_trailing_zeros_of_n.test_zeros module
Test for -> Number of trailing zeros of N!.
Created by Egor Kostan. GitHub: https://github.com/ikostan
- class kyu_5.number_of_trailing_zeros_of_n.test_zeros.ZerosTestCase(methodName='runTest')[source]
Bases:
TestCaseTesting zeros function.
- _classSetupFailed = False
- _class_cleanups = []
- test_zeros = None
- test_zeros_0(**kw)
Testing zeros function with various test data [with number=0, expected=0, message=’Testing with n = 0’].
Testing ‘zeros’ program that should calculate the number of trailing zeros in a factorial of a given number. :return: None
- test_zeros_1(**kw)
Testing zeros function with various test data [with number=6, expected=1, message=’Testing with n = 6’].
Testing ‘zeros’ program that should calculate the number of trailing zeros in a factorial of a given number. :return: None
- test_zeros_2(**kw)
Testing zeros function with various test data [with number=10, expected=2, message=’Testing with n = 10’].
Testing ‘zeros’ program that should calculate the number of trailing zeros in a factorial of a given number. :return: None
- test_zeros_3(**kw)
Testing zeros function with various test data [with number=12, expected=2, message=’Testing with n = 12’].
Testing ‘zeros’ program that should calculate the number of trailing zeros in a factorial of a given number. :return: None
- test_zeros_4(**kw)
Testing zeros function with various test data [with number=30, expected=7, message=’Testing with n = 30’].
Testing ‘zeros’ program that should calculate the number of trailing zeros in a factorial of a given number. :return: None
kyu_5.number_of_trailing_zeros_of_n.zeros module
Solution for -> Number of trailing zeros of N!.
Created by Egor Kostan. GitHub: https://github.com/ikostan
- kyu_5.number_of_trailing_zeros_of_n.zeros.zeros(n) int[source]
Zeros function.
A program that calculate the number of trailing zeros in a factorial of a given number.
N! = 1 * 2 * 3 * … * N
For more info, see: http://mathworld.wolfram.com/Factorial.html
A simple way is to calculate floor(n/5). For example, 7! has one 5, 10! has two 5s. It is done yet, there is one more thing to consider. Numbers like 25, 125, etc have more than one 5.
For example if we consider 28!, we get one extra 5 and number of 0s become 6. Handling this is simple, first divide n by 5 and remove all single 5s, then divide by 25 to remove extra 5s and so on.
Following is the summarized formula for counting trailing 0s. Trailing 0s in n! = Count of 5s in prime factors of n! = floor(n/5) + floor(n/25) + floor(n/125) + ….
- Parameters:
n – int
- Returns:
int
Module contents
Number of trailing zeros of N.