We have a challenge to calculate the hyperfactorial and one to count the trailing zeros of the factorial, so it seems logical to put them together and count the trailing zeros in the hyperfactorial.
As a recap, the hyperfactorial of a number, H(n) is simply Πiⁱ, that is, 1¹·2²·3³·4⁴·5⁵·…·nⁿ. It can be defined recursively as H(n) = nⁿH(n-1) with H(0) = 1. This is integer sequence A002109.
Your task is to write the shortest program or function that accepts a non-negative integer n
and returns or prints the number of trailing zeros in H(n
) when represented as a decimal number (i.e. the corresponding entry from sequence A246839).
n
will be in the range of integers in your language; H(n
) might not be. That means your program must terminate given any non-negative n
that's valid in your language (or 2³² if that's smaller).
Some test cases:
input | output |
---|---|
0 | 0 |
4 | 0 |
5 | 5 |
10 | 15 |
24 | 50 |
25 | 100 |
250 | 8125 |
10000 | 12518750 |
__builtin_ctz( h )
, the number of trailing zero bits. (Which would be the sum of the ctz of each input times its power, I think.) Base 10 explains all the5
s in the answers! :P \$\endgroup\$