Problem #5

How many '1's appear in the following number:

12345678910111213141516...9999989999991000000 ? 12345678910111213141516...9999989999991000000?

It is formed by joining the integers from 1 to 1000000 back-to-back and in order. You should be able to see the ? question mark at the back of the number.

This problem is part of the set Easy Problems


The answer is 600001.

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.

2 solutions

Pranjal Jain
Oct 25, 2014

Consider numbers from 0 to 999999. At each place, probability of every digit is equal i.e. 1 10 \frac{1}{10} . So at each place, "one" will appear 1 0 6 10 = 1 0 5 \frac{10^{6}}{10}=10^5 times. Therefore at 6 places, it will appear 600000 times. In the last number 1000000, it will appear 60000 1 t h 600001^{th} time!!

I know its a bit messy! Hope clean enough to understand!

Anton Shkrunin
Aug 31, 2015

I found the metaphor of one-armed bandit gambling machine useful here.


Consider numbers from 0 to 999999. We can as well add leading 0 to any number below 100000, since it has no effect on the number of 1's in the original string from problem statement. This is handy since we can now let the one-armed bandit have 5 drums numbered from 5 (leftmost) to 1 (rightmost), each containing digits from 0 to 9.

Now, if we know how many 1's are contributed by drum 1, drum 2, etc., and not mixing counts from different drums, the total number of 1's would be of form:

N ( 1 ) M ( 1 ) + N ( 2 ) M ( 2 ) + . . . + N ( 5 ) M ( 5 ) N(1) * M(1) + N(2)* M(2) + ... + N(5) * M(5)

where

  • N ( i ) N(i) is the number of revolutions i i -th drum makes to count from 0 to 999999
  • M ( i ) M(i) is the number of 1's per revolution of i i -th drum when counting from 0 to 999999

Getting at N ( i ) N(i) :

There is 1 0 6 10^6 numbers from 0 to 999999. There must be 1 0 6 / 1 0 i 10^6/10^i number of revolutions of drum i to count to the last number. It can be verified for smaller magnitudes, e.g. 1 0 2 / 1 0 1 10^2/10^1 for numbers 0 to 99.

Given that, N ( i ) = 1 0 6 / 1 0 i N(i) = 10^6/10^i


Finding M ( i ) M(i) :

For i=1, given that we agreed to count 1's on all drums separately, one revolution can only yield one 1's.

For i=2, there are two cases:

  • when the drum shows "1", every turn of 1st drum adds to the count of 1's
  • when the drum shows anything else, turning of 1st drum adds nothing

There's 10 turns of 1st drum when 2nd shows "1".

For i=3

  • when the drum shows "1", every turn of 1st drum adds to the count of 1's
  • otherwise, nothing is added

There's 100 turns of 1st drum when 3rd shows "1".

etc..


Bringing all together

1 0 6 / 1 0 1 1 + 1 0 6 / 1 2 10 + 1 0 6 / 1 0 3 100 + . . . + 1 0 6 / 1 0 6 100000 = 600000 10^6/10^1*1 + 10^6/1^2*10 + 10^6/10^3*100 + ... + 10^6/10^6*100000 = 600000

Since we've not included the 1000000 and the single 1 it provides in our consideration: 6000000 + 1 = 6000000 6000000 + 1 = 6000000 .

The answer is 6000000 6000000 .

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...