12241

Theory:

We know that,

  • From 0-9, each digit occurs once
  • From 0-99, each digit occurs 20 times (10x in position 1 and 10x in position 2)
  • From 0-999, each digit occurs 300 times (100x in P1, 100x in P2, 100x in P3)

If the range is from 0 to a power of 10 then  occurrence of each digit is  N * 10N-1, where N is the power of 10.

Length =7

0000001

0000002

……

0099999

9999900

1234567

If we consider it is a parallelogram of width = 7 and height = 1234567

Then total number of digits = 7 * 1234567 this include trailing and leading zeros(0).

The idea of counting all the digits is like taking the most significant digit and count all the digits from

0 to x*10length-1 (x = most significant digit and length = total number of digits of the given number)

Let’s take 1234567 as the given number.

So total number of digits = total number of digits(from 0 to 1000000-1)

+ total number of digits (from 0 to 200000-1)+ previous most significant digit 1, 234567 times

+ total number of digits (from 0 to 30000-1)+ previous most significant digit 2, 34567 times

+ total number of digits (from 0 to 4000-1)+ previous most significant digit 3, 4567 times

+ total number of digits (from 0 to 500-1)+ previous most significant digit 4, 567 times

+ total number of digits (from 0 to 60-1)+ previous most significant digit 5,      67 times

+ total number of digits (from 0 to 7)+ previous most significant digit 6,

7 times

From total number of digits we found, contains total number of trailing zeros and digits from 1 to 9.

And total number of digits = 7 * 1234567 contains both leading and trailing zeros. So from here we can find the total number of leading zeros by subtracting the previous total number of zeros from 7 * 1234567.

 

 

Solution:

 

Leave a Reply

Your email address will not be published. Required fields are marked *