Finding 0's

How many of the first 1000 positive integers contain the digit 0?

180 181 271 289

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

22 solutions

Ram Mohith
Jul 25, 2018
  • From 1 1 to 100 100 there are 10 \color{#20A900}10 numbers with 0 0 as a digit :

10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 , 100 \quad \color{#E81990}10,20,30,40,50,60,70,80,90,100

  • From 101 101 to 200 200 there are 19 \color{#20A900}19 numbers with 0 0 as a digit :

101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 120 , 130 , 140 , 150 , 160 , 170 , 180 , 190 , 200 \quad \color{#3D99F6}101,102,103,104,105,106,107,108,109,110,120,130,140,150,160,170,180,190,200

  • From 201 201 to 1000 1000 every set of 100 100 numbers follow the same sequence. So, a total of 9 \color{#20A900}9 sets follow this sequence.

Total number of numbers with 0 as a digit = 10 + 9 ( 19 ) \text{Total number of numbers with 0 as a digit = } {\color{#E81990}10} + {\color{#3D99F6}9(19)}

10 + 171 = 181 \implies {\color{#E81990}10} + {\color{#3D99F6}171} = {\color{#20A900}181}

Why is 1 1 being subtracted from 10 + 9 ( 19 ) = 181 10+9(19)=181 ?

Michael Mendrin - 2 years, 10 months ago

Log in to reply

I think the answer should be 181, and likely "1000" was forgotten. I've updated it accordingly.

Calvin Lin Staff - 2 years, 10 months ago

why we won't consider 80 From 1 to 100 there are 10 numbers with 0 as a digit ?
Actually we need to consider 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 so there are 11 numbers with 0 as a digit right?

hari palani - 2 years, 10 months ago

Log in to reply

Yeah he missed writing 80 there

Shreeram Petkar - 2 years, 10 months ago

Sorry, that is a typing mistake. Actually the number of digits with 0 from 1 to 100 are 10 but I forgot to write 80. Thanks for informing. I have edited my solution.

Ram Mohith - 2 years, 10 months ago

I forgot about the 1000

Ahmad Fikri Azhari - 2 years, 10 months ago

Log in to reply

That is the place where most them go wrong. They will be confusion whether to count 1000 or not.

Ram Mohith - 2 years, 10 months ago

Between 1-99, there are 9 x 1 of the digit 0 appearing: 10, 20, 30... 70, 80 and 90. 9 x 1 is 9.

Then, between 100,199, the digit 0 appears 1x2 (In 100) + 9x1 (101, 102, ..., 108, 109) + 9x1 (110,120, ..., 180,190) times. This is equal to: 2 + 9 + 9 times, so 20 times.

This pattern will continue 9 times, as the sequence will follow as: 100-199, 200-299, ..., 800-899 and 900-999. 20 x 9 = 180.

Finally, the 3 zeroes from 1,000 will be counted.

9 + 180 + 3 = 192 zeroes between 1-1,000.

And if you still don't believe this, go on to this site: https://www.quora.com/How-many-time-digit-0-appears-from-1-to-1000

Hope this helps.

Andrew Wee - 2 years, 10 months ago

Log in to reply

It seems you are counting both the 0 s 0's in 100 100 . This method is correct when the question asks for Find the number of zeros in positive integers less than 1000 ? . But here in this case the question only asks for Find the number of positive integers below 1000 containing the digit zero ?

Ram Mohith - 2 years, 10 months ago

Log in to reply

Oh... 😂😂 my fault What a mistake Thx alot Mr. Mohith

Andrew Wee - 2 years, 10 months ago

Log in to reply

@Andrew Wee No problem. Your point is also correct. But just answered a different question. Sometimes failures for one thing gives success for another one !!!

Ram Mohith - 2 years, 10 months ago

I knew 0 wasn't negative, but not that (despite sans "-") it wasn't positive. I guess it is a bit like 12:00 AM (usually!) comes almost immediately before 12:00:01 PM. So, I prefer military time, and ask people to tell me 'noon' or 'midnight', so we don't get it wrong.

J B - 2 years, 10 months ago

Log in to reply

In my working out - I started from 0 (since it is a positive integer), but excluded 1000, since (when you start from 0) the first 1000 integers are from 0 to 999 - so the sum works out the same. If you go from 0 to 1000, you actually count 1001 integers.

Tony Flury - 2 years, 10 months ago

Log in to reply

Actually, 0 isn't a positive integer (esp on Brilliant). Though that statement could depend on where you are based.
I am almost certain that the UK unanimously consider 0 not-positive (and not-negative). The French consider 0 both positive and negative.

Good observation that both 0 and 1000 include 0, so it will not change the answer to the problem.

Calvin Lin Staff - 2 years, 10 months ago

Is there an easier way? I'm really bad at maths, so I don't really get this. Can someone please help?

Evelyn TENG [5J] - 2 years, 10 months ago

Log in to reply

This is the most easiest way. For better understanding I wrote every thing in detailed. Otherwise you can directly solve this number. You use you creative power at its best. You know there are 10 number which contain 0 from 1 - 100. Also you know that there are 19 numbers from 101 - 200 which contain 0. So, the total numbers are 10 + 9 ( 19 ) = 181 10 + 9(19) = 181 .

I know that you may feel this tough but once you are used to it you will find it better. The same is the case with me. When I joined brilliant I felt it very tough but after that I got used to it and now my thinking power increased a lot. Don't be discouraged !!!

Ram Mohith - 2 years, 10 months ago

Read Emil's solution about counting the complement (numbers without a 0), which I feel is an easier way to progress, though not necessarily the first approach that someone would think of.

Calvin Lin Staff - 2 years, 10 months ago
Stephen Mellor
Jul 28, 2018

Since the number can't begin with a zero, it is either a multiple of 10 10 (ending in a zero), or of the form a 0 b \overline{a0b} where a , b 0 a,b\neq0 to avoid double counting numbers that fall into the first situation.

There are 1000 10 = 100 \dfrac{1000}{10} = \color{#D61F06}{100} multiples of 10 10 for the first situation (this goes up to and including 1000 1000 ).

For the second situation, there are 9 9 possibilities independently for a a and b b so there are 9 × 9 = 81 9 \times 9 = \color{#D61F06}{81} integers.

100 + 81 = 181 \color{#D61F06}{100} \color{#333333}{ + } \color{#D61F06}{81} \color{#333333}{= \boxed{181}}

Such a fresh solution!

Leonid Gremyachikh - 2 years, 10 months ago

i love this method rather than simple counting. Good job!

A Former Brilliant Member - 2 years, 10 months ago

Log in to reply

Whom do you think is simply counting ? Is it me ?

Ram Mohith - 2 years, 10 months ago

9 two-digit numbers contain zero:10,20,30,40,50,60,70,80,90. 1000 also contains zero. There are 900 three-digit numbers. Those that do not contain zero are with digits between 1 to 9. Therefore we have 9 3 9^3 =729 three-digit numbers with no zero or 900-729=171 three-digit numbers containing zero. The total of all numbers from 1 to 1000, containing zero is 9+1+171=181

"The total of all numbers between 1 and 1000." The numbers on the end of the range, are not 'between'. So, "...from 1 to 1000."

J B - 2 years, 10 months ago

Log in to reply

I agree and it's fixed.Thank you!!!

A Former Brilliant Member - 2 years, 10 months ago

It's easier to count the complement: all the numbers that don't contain a 0.

  • Of all the single-digit numbers there are 9 that don't have a 0
  • Of all the two-digit numbers there are 9 * 9 = 81 that don't have a 0
  • Of all the three-digit numbers there are 9 * 9 * 9 = 729 that don't have a 0

That means there are a total of 9 + 81 + 729 = 819 numbers that don't contain a 0. Therefore there are 1000 - 819 = 181 \boxed{181} numbers that do contain a 0.

Cheers for contrarians! (However, 0 is a number, perhaps just not a 'positive' number.)

J B - 2 years, 10 months ago

I did it the same way!!!

PAULO BOUHID - 2 years, 10 months ago
1
2
3
4
5
c = 0
for i in range(1,1001): # 1 to 1000
    if '0' in str(i):
        c += 1
print count

1
181

Same solution as above with list comprehension: sum([1 for i in range(1, 1001) if '0' in str(i)])

Laszlo Uveges - 2 years, 10 months ago
Jochen Morent
Jul 30, 2018

One tenth of the integers from 1 to 1000 have a 0 as their last digit.

One tenth of the integers from 100 to 1000 have a 0 in their second digit.

The only number having a 0 in its third digit is already part of both other groups.

One tenth other the second group (0 in the second digit) is also part of the first group.

Thus there are: 1000/10 from the first group; 900/10 for the second group; (900/10)/10 for the overlap of the groups.

This makes 100 + 90 - 9 = 181

Ricardo Barbosa
Jul 30, 2018
1
2
3
4
5
6
#!/usr/bin/env python3
#python brute force by norsigma.com
count=0
for i in xrange(1,1000+1):
    if '0' in str(i): count = count + 1
print(count) 

From all the 10s, 10, 20, 30 , 40, ... 1000 = 100 zeros. Only the first 10 numbers of each 100 i.e 101-109, 201-209, ... 901-909, there are 9 zeros in each column - 9*9 == 81 zeros. So this makes a total of 100 + 81 zeros = 181.

Mohit Aneja - 2 years, 10 months ago
Eric Lucas
Jul 30, 2018

Numbers containing zeros have the following distinct forms and counts (x, y can be any non-zero digit):

X0..........9 possibilities

X0y........9*9=81 possibilities

Xy0........9*9=81 possibilities

X00........9 possibilities

1000......1 possibility

Since x and y are non-zero, there are no numbers that are double-counted.

9+81+81+9+1=181

Kelvin Hong
Jul 30, 2018

Supposed we want to find the number doesn't contain 0 0 , three digits number will be 729 729 , two digits number will be 81 81 , and single-digit will be 9 9 . Thus, there are 1000 729 81 9 = 181 1000-729-81-9=181 numbers contain 0 0 .

Isn't there a pattern exist, is it ? 1000 9 3 9 2 9 = 181 1000 -9^3-9^2-9 =181 .

Naren Bhandari - 2 years, 10 months ago

Log in to reply

Yeah, I noticed it but just write it other way.

Kelvin Hong - 2 years, 10 months ago
Meera Kalluraya
Jul 29, 2018

There are 10 from one to 100. 9 from 200-300 9 from 300-400 9 from 400 to 500 and 9 for everything else. Ad them up, you get 181

Please modifiy: there 10+9 from 200-300 etc.

Giuseppe Saccone - 2 years, 10 months ago
Alistair Morgan
Aug 5, 2018

If you look at 0s in the 1s place that happens, in a set of numbers from 1-100 or 901-1000 (example 950), 10 times. That happens 10 times between 1-1000 so 10 times 10 equals 100 numbers.

Then there is 0s in the 10s place. That happens 9 times in a set of numbers from 101-200 (not including ones with 0s in the 1s place) and that only happens 9 times between 1-1000 because it doesn't happen between 1-99 as it needs 3 digits to have a 0 in the 10s place so 9 times 9 equals 81.

100+81=181 =>QED

Amir Teymuri
Aug 5, 2018

From 1 to 100 only multiples of 10 has zeros (10, 20, 30, ...). From 1 to 1000 there are 10 times such series (10, 20, ..., 110, 120, ..., 210, 220, ...): 10 10 = 100 10 * 10 = 100 .

Plus from 100 on, the first 9 numbers will also get a zero (101, 102, 103, ..., 109). From 100 to 1000 there are 9 such series (101, 102, ..., 201, 202, ..., 301, 302, ...): 9 9 = 81 9 * 9 =81 .

The total number of zeros is the sum of these: 100 + 81 = 181 100 + 81 = 181

Huon Smith
Aug 5, 2018

In the first 100 there is 10, 20, 30 etc up to 100 which makes 10. From 100-200, there is 101, 102, 103 etc up to 110. Then there is 120, 130 etc up to 200. That makes 19. Each hundred after this follows the exact same number since the only thing that changes is the first digit. So that makes 9 sets of 19 + the 10 from 1-100. That makes 181. It does say the first 1000 positive integers so I thought it would include 1000 but it doesn't otherwise the answer would be 182.

Li Jin
Aug 3, 2018

Avanish P
Aug 3, 2018

The required number can be of the form(here [RN] means a random number that can be 1,2,3,4,5,6,7,8,9)

(1)[RN]0 In this [RN] can have 9 values hence their are 9 such numbers (2)[RN][RN]0 in this each [RN] can have 9 values hence total=9×9=81 (3)[RN]0[RN] in this again each [RN] can have 9 values total=9×9=81 (4)[RN]00 in this[RN] can have 9 values hence their are 9 such numbers (5)1000 their is only 1 such number TOTAL=9+81+9+81+1=181

Sorry if this is a repeat of any other previous solution, I just want to share how I came to a solution :-)

Integers # of Zeros comment
1 - 10 1 only integer 10 contains a zero
1 - 100 10 every 10'th contains a zero
1 - 200 20+9 every 10'th contains a zero, plus 101-109
1 - 300 30+9+9 every 10'th contains a zero, plus 101-109 plus 201-209
1 - 400 40+9+9+9 every 10'th contains as a zero, plus 101-109 plus 201-209 plus 301-309
1 - 500 50+9+9+9+9 every 10'th contains a zero, plus 101-109 plus 201-209 plus 301-309 plus 401-409
1 - n n being any positive integer evenly divisible with 100

the above implies that the number of integers containing at least one zero could be generalised to

n 10 \frac{n}{10} + 9 × ( n 100 \frac{n}{100} -1)

So for n = 1000

1000 10 \frac{1000}{10} + 9 × ( 1000 100 \frac{1000}{100} - 1) = 100 + 9 × (10 - 1) = 100 + 81 = 181

Jesse Nieminen
Aug 1, 2018
1
sum([1 if "0" in str(i) else 0 for i in range(1, 1001)])

Matko Štokov
Aug 1, 2018

I'm having a little trouble understanding this although I arrived to the same conclusion, only with a slightly different method. Now, from positive integers to a 1000 exclude zero itself and include 1000 itself, so you have 1 digit numbers, 2 digit numbers, 3 digit numbers, and a 4 digit number.

_ - 1 digit numbers: 9 of them don't have a zero: 9^1 = 9 numbers

_ _ - 2 digit numbers: on "ones", 9 numbers don't have a zero, and on "tens" 9 numbers don't have a zero: 9^2 = 81 numbers

_ _ _ - 3 digit numbers: on "ones", 9 numbers don't have a zero, on "tens" 9 numbers don't have a zero, and on "hundreds" 9 numbers don't have a zero: 9^3 = 729

Now 9+81+729 = 819 numbers don't have a zero, meaning that 999-819 = 180 do have a zero. And if we add the "1000", that makes it 181 numbers that have a zero. BUT wouldn't this mean that that includes zeros in places of "hundreds" in three digit numbers (9 of them), and zeros in places of "tens" in two digit numbers (also 9 of them)? That is: shouldn't it be 181-18 = 163?

Between 1 - 100 } 10 no.s

Between 100 - 200 } 10 + 9 no.s (Numbers in the form of x 0 y \overline{x0y} )

Between 200 - 300 } 19 no.s (( Same rule applies ))

Between 300 - 1000 } 19 × \times 7

\therefore between 1 - 1000 = 10 + 19 + 19 + (19 × \times 7) = 181 \large \color{#20A900} 181

Michael Esplin
Jul 31, 2018

Any multiple of 10 has a 0. There are 100 "10s" in a 1000.

101 has 0 in it too. So we need to include all solutions like 101.

The number 101 is of the form a0b where a and b are digits.

We know b can't be 0 because we already did that and a can't be 0 because that doesn't make sense.

Thus a is 1-9 and b is 1-9. We know 9x9 = 81.

100 + 81 = 181.

Ann Fisher
Jul 31, 2018
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
public static void main(String[] args) {
        int count = 0;
    for (int n = 1; n <= 1000; n++){
            if(String.valueOf(n).contains("0")){
                count += 1;

            }

        }
        System.out.print(count);
  }

or just in linux command line: seq 1 1000 | grep 0 | wc -l

Frode Fjeldbo - 2 years, 9 months ago
Prabesh Humagain
Jul 31, 2018

Its 100 // coz 10,20,30,.... //+81 // a01a02a03...a09 for all a belongs N 1-9 //

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...