-1
$\begingroup$

This question already has an answer here:

Okay i need to see if there is a formula to calculate how many 0's are between two given number for example the number of 0's between 100 and 200 is 20 and the number of 0's between 1234567890 and 2345678901 is 987654304, is there a reliable equation that can calculate this number? (note: 100 counts as two 0's 1000 is three and 101 is one)

$\endgroup$

marked as duplicate by Rohan, Chris Culter, user91500, JMP, Magdiragdag Feb 22 '17 at 7:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Also some recent techniques here: Writing Out The Number of Zeros From 1 - 1,000,000 $\endgroup$ – Joffan Feb 22 '17 at 6:08
  • $\begingroup$ You might want to mention how you know the answer for 1234567890 and 2345678901. $\endgroup$ – Qudit Feb 22 '17 at 6:16
  • $\begingroup$ Between 100 and 200 there are 18 zeros, not 20: 101 through 109 plus 110 through 190, that is 9+9. Unless you include exactly one of those two bounding numbers (but you didn't specify that). $\endgroup$ – CiaPan Feb 22 '17 at 6:28
1
$\begingroup$

The number of zero digits in a positive integer $k$ is:

$$\sum\limits_{i=0}^{\log_{10}{k}}1-\left\lceil\frac{\left\lfloor\frac{k}{10^{i}}\right\rfloor-10\left\lfloor\frac{k}{10^{i+1}}\right\rfloor}{10}\right\rceil$$


The number of zero digits in the range $[1,n]$ is therefore:

$$\sum\limits_{k=1}^{n}\sum\limits_{i=0}^{\log_{10}{k}}1-\left\lceil\frac{\left\lfloor\frac{k}{10^{i}}\right\rfloor-10\left\lfloor\frac{k}{10^{i+1}}\right\rfloor}{10}\right\rceil$$


The number of zero digits in the range $[m,n]$ is therefore:

$$\left(\sum\limits_{k=1}^{n}\sum\limits_{i=0}^{\log_{10}{k}}1-\left\lceil\frac{\left\lfloor\frac{k}{10^{i}}\right\rfloor-10\left\lfloor\frac{k}{10^{i+1}}\right\rfloor}{10}\right\rceil\right)-\left(\sum\limits_{k=1}^{m-1}\sum\limits_{i=0}^{\log_{10}{k}}1-\left\lceil\frac{\left\lfloor\frac{k}{10^{i}}\right\rfloor-10\left\lfloor\frac{k}{10^{i+1}}\right\rfloor}{10}\right\rceil\right)$$

$\endgroup$
  • $\begingroup$ for the number of zero digits in the range [m,n] what is k, n, and i? sorry my understanding of it is pretty basic. if i were to write this as a program what am i plugging into k n and i in the equation? $\endgroup$ – Jacob Bowman Feb 22 '17 at 15:57
  • $\begingroup$ @JacobBowman: In the last formula, k and i are intermediate variables. k is your counter in the outer loop, and i is your counter in the inner loop. $\endgroup$ – barak manos Feb 22 '17 at 16:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.