What is sum of occurrences of zeros, at the end of integers, up to number $n$ ? Let's call this function $O(n)$
Examples :
$1,2,3,4,5,6,7,8,9,10,$so $O(10)=1$
$1,...,20,$ so $O(20)=2$
$O(100)=11$
$O(200)=22$
$O(300)=33$
$O(300)=33$
$O(1000)=111$
2026-05-05 03:38:10.1777952290
On
What is sum of occurrences of zeros, at the end of integers, up to number $n$?
148 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
There are 2 best solutions below
3
On
If you want the number of zeros less than a number $n$, note that a zero gets added if we hit a multiple of $10$, $2$ zeros get added if we hit a multiple of $100$ and in general $k$ zeros get added if we hit a multiple of $10^k$. Hence, the number of zeros is $$\left\lfloor\dfrac{n}{10}\right\rfloor + \left\lfloor\dfrac{n}{10^2}\right\rfloor + \left\lfloor\dfrac{n}{10^3}\right\rfloor + \cdots$$
Given a number $n$, the number within the range (1,n) with the most occurrence of trailing zeros is
=number_of_digits_in_n - 1=$\log(n)$ So we need to find the occurrence of multiple of $10_s$ upto $10^{\lfloor \log(n) \rfloor}$. Each occurrence is $\lfloor \frac{n}{10^i}\rfloor \forall i\le\lfloor \log(n) \rfloor$ So we just have to sum all such occrances$$O(n)=\sum^{\lfloor \log(n)\rfloor}_{i=1} \left\lfloor\dfrac{n}{ 10^i}\right\rfloor $$