Maybe I'm reading it wrong, but isn't the sum of the digits of 1-10 just 11? 1 digit for 1-9, 2 digits for 10-99? So it's 9+90*2+900*3+9000*4+90000*5+900000+6

Trader Interview New York, NY

Jane Street## What is the sum of the digits of all the numbers from 1 to

1000000? This is different from the sum of the numbers. For instance the sum of the numbers from 1 to 10 is 55 whereas the sum of the digits is 46.

Tags:

brain teaser, math See More, See Less8

17 Answers

▲

1

▼

Maybe I'm reading it wrong, but isn't the sum of the digits of 1-10 just 11? 1 digit for 1-9, 2 digits for 10-99? So it's 9+90*2+900*3+9000*4+90000*5+900000+6

▲

3

▼

no, I think the easy way to solve it in your head is to remember that when adding all digits 1 to 100, you have 50 pairs: 1+100, 2+99, etc. Each pair is 101, times 50 is 5050.

1 to 1000 would be 500500

so 1 to 1,000,000 would be 500,000,500,000

Pretty cool, huh?

▲

7

▼

scott, dude you should add digits not the numbers, so 99+2 = 18+2 =20. not 101

▲

2

▼

Scott's answer from May 24 is the correct way to think about it if summing the numbers.

▲

2

▼

The answer is 27,000,001 - if you do it programatically the operation is a simple map reduce - simply map a digit sum function across the list of values [1, 1000000] and then reduce an addition operator across the result.

Python Proof:

>>> sum(map(lambda n: sum(map(int, str(n))), xrange(1, 1000001)))

27000001

▲

0

▼

21085156

▲

2

▼

Don't mind the above answer. I read the question wrong.

▲

8

▼

Each digit will appear 1+10+100+1000+10000+100000 times. so the answer is 111,111*45+1=4444440+555555+1=4999996

▲

4

▼

nb is right. Another way you can think about it easily is if you want the digits from 1 to 1,000,000 then each digit should appear 1/10 * 1,000,000 times.

So

100,000 x 6 (for each place value) x 45 (the sum from 1 to 9) + 1 (for the 1 million)

27,000,001

▲

1

▼

I think John Doe is right.

▲

15

▼

27,000,001 is what I got. Think of each number as a 6 digit number. The average number each digit could be from 000,000 to 999,999 is (9+0)/2=4.5. Since the average of each number is 4.5 and there are 6 digits the average sum of the digits for a 6 digit number should be 4.5*6=27. There are 1 million numbers from 000,000 to 999,999 so the sum of the digits from 000,000 to 999,999 is 27,000,000. Subtract the digits of 000,000 which is just 0 and add the digits of 1,000,000 which is just 1 to get 27,000,001.

▲

0

▼

For arbitrary a=1,...,9 accounts the how many a's appear in the six digit number.

1 * C(6,1)*9^5 + 2* C(6,2)*9^4 + 3 * C(6,3) * 9^3 + 4*C(6,4)*9^2 + 5*C(6,5)*9 +6*C(6,6) = 600000.

600000*(1+2+3+...+9)= 27000000.

Then add the 1 from 1000000. The ans is 27000000.

▲

0

▼

2.7 x 10^7 + 1

▲

4

▼

general rule:

to 10^n

answer is 10^n * n * 4.5+1

here n=6, result is 27 000 001

▲

0

▼

1-1000000 same as sum of digits in 0 - 999999 then plus 1, treat 0 - 999999 as a 6 digit random number, then the digit of sum is sum of digit for each number: 1000000*(4.5*6)=27000000, so answer is 27000001.

▲

0

▼

John doe is right

each batch of 1-9 appears 10^(# before line times) i.e. 10000|0, 1-9 appear in the ones place 100,000 times, adding 100,000*45 to your sum. Thus we can write the sum 111,111 (1 for each place) *45 +1

To comment on this, Sign In or Sign Up.

Would you like us to review something? Please describe the problem with this {0} and we will look into it.

Your feedback has been sent to the team and we'll look into it.

The main idea is that if you write all the numbers from 0 to 999999 down as six digit numbers (possibly prepending zeros) then all digits appear the same number of times. So, its digit appears exactly 6 x 1000000/10 = 600000 times. so the result is 600000x 45 +1 (+1 for the number 1000000)