OFFSET
1,1
LINKS
EXAMPLE
a(1) = 2 to start the race. At 15! the number of final twos is 5 and so is the number of eights. But at 16, eights now lead twos, so a(2) = 16 to reflect this fact.
When k=10000 is reached, the count stands at 2509 twos, 2486 fours, 2494 sixes, and 2510 eights.
MATHEMATICA
f[ n_Integer, m_Integer ] := (c = 0; p = 1; While[ d = Floor[ n/5^p ]; d > 0, c = c + d; p++ ]; Mod[ n!/10^c, m ]); a = Table[ 0, {4} ]; r = 4; Do[ b = f[ n, 10 ]; Switch[ b, 2, a[ [ 1 ] ]++, 4, a[ [ 2 ] ]++, 6, a[ [ 3 ] ]++, 8, a[ [ 4 ] ]++ ]; If[ a[ [ b/2 ] ] > a[ [ r/2 ] ], r = b; Print[ n ] ], {n, 2, 10^4} ]
PROG
(Python)
from functools import reduce
from itertools import count, islice
from sympy.ntheory.factor_ import digits
def A058376_gen(): # generator of terms
a, k, i = [0]*4, 0, 1
for n in count(2):
m = (reduce(lambda x, y:x*y%10, ((1, 1, 2, 6, 4)[a]*((6, 2, 4, 8)[i*a&3] if i*a else 1) for i, a in enumerate(digits(n, 5)[-1:0:-1])))*6%10>>1)-1
a[m] += 1
if a[m] > k:
if m!=i:
yield n
i, k = m, a[m]
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Robert G. Wilson v, Dec 19 2000
EXTENSIONS
Offset 1 from Michel Marcus, Jul 25 2021
STATUS
approved