| Bytes | Lang | Time | Link |
|---|---|---|---|
| 050 | AWK | 250929T140014Z | xrs |
| 021 | APLNARS | 250928T190213Z | Rosario |
| 054 | Wolfram Language Mathematica | 250927T113930Z | 138 Aspe |
| 048 | Scala 3 | 230805T122937Z | 138 Aspe |
| 047 | Retina 0.8.2 | 230802T073706Z | Neil |
| 010 | 05AB1E | 230802T073950Z | Kevin Cr |
| 031 | C gcc | 230802T151154Z | c-- |
| 038 | Python 3.8 prerelease | 230801T091132Z | loopy wa |
| 047 | Desmos | 230801T220351Z | Aiden Ch |
| 041 | JavaScript Node.js | 230801T072725Z | l4m2 |
| 030 | PARI/GP | 230801T120057Z | alephalp |
| 058 | Python 2 | 230801T064413Z | The Thon |
| 005 | Jelly | 230801T115031Z | Jonathan |
| 049 | C gcc | 230801T114333Z | Noodle9 |
| 425 | Vyxal s | 230801T074659Z | lyxal |
| 068 | Excel | 230801T085029Z | Jos Wool |
| 016 | Charcoal | 230801T084543Z | Neil |
AWK, 50 bytes
{for(x=1;$0;match(x,/0+$/))x*=$0^$0--}1,$0=RLENGTH
Doesn't work in ATO with large numbers, but should work locally if you try:
awk -M '{for(x=1;$0;match(x,/0+$/))x*=$0^$0--}1,$0=RLENGTH' <<< 10
Replace the 10 with your input number. Works up to at least 250, but it's slow (I tried 10000 and it's been running for a minute...).
APL(NARS), 21 chars
{⍵≤0:⍵⋄5×+/(∇,⍳)⌊⍵÷5}
It would apply the formula of "loopy walt" post. It apply the formula below too.
(2÷⍨k×1+k)=+/⍳k
test:
f←{⍵≤0:⍵⋄5×+/(∇,⍳)⌊⍵÷5}
f 0
0
f 4
0
f 5
5
f 250
8125
f 10000
12518750
f 10000000000x
WS FULL
f 10000000000x
∧
probably it because there are problem in doing ⍳⌊10000000000x÷5 but here no problem:
{⍵≤0:⍵⋄5×(∇k)+2÷⍨k×1+k←⌊⍵÷5}10000000000x
12500000041240234375
Wolfram Language (Mathematica), 54 bytes
Port of @loopy walt's Python answer in Mathematica.
Golfed version. Try it online!
f=If[#<1,0,With[{m=#~Quotient~5},(f[m]+m*(m+1)/2)*5]]&
Ungolfed version. Try it online!
(* Define the recursive function f *)
f[n_Integer] := If[n < 1, 0,
Module[{m = Quotient[n, 5]},
(f[m] + m*(m + 1)/2)*5
]
]
Scala 3, 48 bytes
Port of @loopy walt's Python answer in Scala.
n=>{if(n<1)0 else{val m=n/5;(f(m)+m*(m+1)/2)*5}}
Retina 0.8.2, 47 bytes
.+
$*¶
$.`$*#$.`$*
+%`^(#+)\1{4}\b
$'¶$1
A`#
1
Try it online! Link includes Link includes faster test cases (since it calculates in unary internally, it times out TIO after about 3000 and probably runs out of memory anyway after about 30000). Explanation:
.+
$*¶
$.`$*#$.`$*
Generate a range from 0 up to and including the input, in duplicated unary, once using # and once using 1.
%`^(#+)\1{4}\b
$'¶$1
For each entry that has a multiple of 5 #s, remove them leaving the 1s, and then append an entry with the number of #s divided by 5, but with the original number of 1s.
+`
Repeatedly process any new entries that have a multiple of 5 #s.
A`#
Remove all entries that weren't a multiple of 5 #s. (If they were, the #s would have been removed.)
1
Count the number of trailing zeros.
Retina 1 can do the whole calculation in decimal, allowing it to quickly compute the result for 10000, although it does take 65 bytes:
.+
*¶
$.`
+%`.*50*$
$.(*2*
~["L$`^¶$.("|""L$rm`0*$
$.($:&*$&)$*_
Try it online! Link includes test cases. Explanation:
.+
*¶
$.`,$.`
Generate a range from 0 up to and including the input.
+%`.*50*$
$.(*2*
Double any value that ends in 5, 50, 500 etc. as many times as necessary so that it does not.
["L$`^¶$.("|""L$rm`0*$
$.($:&*$&)$*_
Multiply each original value by the number of trailing zeros, then generate a command that calculates the sum of those products. The intermediate multiplication allows use of a capture on the right which would otherwise have to be wrapped. The match is performed right-to-left so that values with trailing zeros are only matched once but matches without trailing zeros are also matched so that the match index will give the original value.
~`
Execute that command.
05AB1E, 16 10 bytes
LDmTªPγθg<
-6 bytes thanks to @lyxal.
Actually calculates \$H(n)\$ and counts the amount of trailing 0s, so this is a much slower approach. Still valid though, since the new 05AB1E is built in Elixir, which has an infinitely large integer and is only limited by memory (in the legacy version of 05AB1E, built in Python, it would be valid as well for the same reason).
Try it online or verify (almost) all test cases.
Explanation:
L # Push a list in the range [1, (implicit) input-integer]
D # Duplicate it
m # Take the power of the values at the same positions: [1**1,2**2,3**3,...]
Tª # Append a 10 to this list
P # Take the product
γ # Group adjacent equal digits together in substrings
θ # Pop and keep the trailing part of 0s
g # Pop and push its length
< # And decrease it by 1
# (after which the result is output implicitly)
The Tª and < are only there for inputs in the range \$0\leq n<4\$. For \$n\geq5\$ it works fine without it. These three bytes also have loads of alternatives (i.e. LDmP0«γθ¦g; LDmPγθgDi0; LDmPγθgD≠*; etc.), but I've been unable to find anything shorter thus far.
Original 16 12 bytes approach:
ƒNÐ5sm¿5.n*O
Port of AidenChow's Desmos answer, so make sure to upvote that answer as well!
Try it online or verify all test cases.
Explanation:
ƒ # Loop `N` in the range [0, (implicit) input-integer]:
NÐ # Push three copies of `N` to the stack
N 5sm # Pop one, and push 5 to the power `N`
N ¿ # Pop this and another `N`, and push their Greatest Common Divisor
5.n # Take log_5 of that value
N * # Multiply it by the remaining `N`
O # Sum all values on the stack together
# (after which the result is output implicitly)
05AB1E lacks the convenient multiplicity-builtin that the Jelly and Vyxal answers have, although I still have the feeling this can be shorter with another approach, since the EDIT: which was indeed correct.5sm and 5.n are rather verbose.
Python 3.8 (pre-release), 38 bytes
f=lambda n:n and(f(m:=n//5)-m*~m//2)*5
How?
Calculates the number almost directly only recursing to correct for higher powers of 5 in the base:
$$\begin{align} f(n) & =\sum_{i=5,10,...,n} i+\sum_{i=25,50,...,n}i+\sum_{i=125,250,...,n}i+... \\ & =5 \sum_{i=1}^\left\lfloor\frac n 5 \right\rfloor i + 25 \sum_{i=1}^\left\lfloor\frac n {25} \right\rfloor i + 125 \sum_{i=1}^\left\lfloor\frac n {125} \right\rfloor i + ... \\ & = 5 \sum_{i=1}^\left\lfloor\frac n 5 \right\rfloor i + 5 f\left(\left\lfloor\frac n 5 \right\rfloor\right) \\ & = 5 \frac{\left\lfloor\frac n 5 \right\rfloor\left(\left\lfloor\frac n 5 \right\rfloor+1\right)}2 + 5 f\left(\left\lfloor\frac n 5 \right\rfloor\right)\end{align}$$
Desmos, 47 bytes
f(k)=∑_{n=1}^knlog_5(gcd(n,5^{ceil(log_5n)}))
Try It On Desmos! - Prettified
It can be f(k)=∑_{n=1}^knlog_5(gcd(n,5^n)) but that quickly runs into inaccuracies even for smaller inputs.
JavaScript (Node.js), 41 bytes
f=n=>n&&f(~-n)+g(n)*n
g=n=>n%5?0:-~g(n/5)
-3 bytes from Arnauld
JavaScript (Node.js), 29 bytes
f=n=>n&&f(n=n/5|0)*5-n*~n/2*5
Port of loopy walt's
Python 2, 58 bytes
f=lambda n:n and f(n-1)+g(n)*n
g=lambda i:i%5<1and-~g(i/5)
Python 2, 39 bytes
f=lambda n:n and(f(n/5)-n/5*~(n/5)/2)*5
Port of loopy walt's Python answer.
Jelly, 5 bytes
ọ€5ḋR
A monadic Link that accepts a non-negative integer, \$n\$, and yields the number of trailing zeros of the hyperfactorial, \$H(n)\$.
How?
As the hyperfactorial's input increases, each time \$n\$ reaches a multiple of five \$n\nu_5(n)\$ more zeros are added.
ọ€5ḋR - Link: non-negative integer, n
€ - for each {i in [1..n]}:
ọ 5 - {i} order of multiplicity of {5}
R - range {n} -> [1..n]
ḋ - dot-product
Vyxal s, 34 bitsv2, 4.25 bytes
ɾ:5Ǒ*
-7 bits thanks to emanresu
Explained
ɾ:5Ǒ*
ɾ # The range [1, input]
: # Duplicated
5Ǒ # With the multiplicity of 5 of each number
* # Multiply that by the original list
# The s flag sums the list
💎
Created with the help of Luminespire.
Excel, 68 bytes
=LET(a,SEQUENCE(A1),IFERROR(SUM(N(TEXTSPLIT(PRODUCT(a^a),,0)="")),))
Input in cell A1. Fails for A1>7.
Charcoal, 16 bytes
IΣE⊕N×ι⌕⮌X⁰↨ι⁵¦⁰
Try it online! Link is to verbose version of code. Explanation:
N Input integer
⊕ Incremented
E Map over implicit (inclusive) range
ι Current value
× Times
⁰ Literal integer `0`
X Vectorised raise to power
ι Current value
↨ Converted to base
⁵ Literal integer `5`
⮌ Reversed
⌕ Find index of
⁰ Literal integer `0`
Σ Take the sum
I Cast to string
Implicitly print