# Count the number of 0's between two given numbers [duplicate]

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)

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

• Also some recent techniques here: Writing Out The Number of Zeros From 1 - 1,000,000 – Joffan Feb 22 '17 at 6:08
• You might want to mention how you know the answer for 1234567890 and 2345678901. – Qudit Feb 22 '17 at 6:16
• 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). – CiaPan Feb 22 '17 at 6:28

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)$$

• 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? – Jacob Bowman Feb 22 '17 at 15:57
• @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. – barak manos Feb 22 '17 at 16:30