The function f ( x ) is the sum of digits of x ; for example: f ( 2 4 ) = 6 , f ( 7 8 ) = 1 5 , and f ( 1 4 4 ) = 9 (note that f ( 9 9 ) = 1 8 and not 1 + 8 = 9 ).
Find f ( 1 ) + f ( 2 ) + f ( 3 ) + ⋯ + f ( 1 0 0 0 ) .
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.
The question asks for the sum of the sum of the digits of integers from 1 to 1000.
This sum won't change, if we add the 0. So let's write all numbers from 0 to 999 (1000 numbers) with three digits (e.g. 0 = 000, 7 = 007, 12 = 012, 789 = 999) as a first step.
Since all the 10 digits from 0 to 9 occur equally likely (each of them 1000 / 10 = 100 times at each place (units, tens, hundreds)), therefore the sum of the digits for one place is:
1 0 0 × ( 0 + 1 + 2 + . . . + 8 + 9 ) = 1 0 0 × 2 1 0 × ( 0 + 9 ) = 4 5 0 0
The sum of sum of digits for integers from 0 to 999 (or from 1 to 999) is three times as much as this (3 places):
3 × 4500 = 13500
And the sum from 1 to 1000 is just our sum from 1 to 999 and the sum of the digits of 1000 (1 + 0 + 0 + 0 = 1):
1 3 5 0 0 + 1 = 1 3 5 0 1
Hence, our answer is "None of the other choices".
class MyClass {
public static void main(String[ ] args) {
int sum=0;
for(int n=1;n<=1000;n++){
int b=Integer.toString(n).length();
for(int a=0;a<=b-1;a++){
sum+=(int)(n/(Math.pow(10,a)))%10;
}
}
System.out.println(""+sum);
}
}
OUTPUT 13501
Problem Loading...
Note Loading...
Set Loading...
We note that the sum of digits of 4-digit numbers is the sum of sum of individual unit, ten, hundred, and thousand digits. Let n = d 3 d 2 d 1 d 0 , then we have:
n = 1 ∑ 1 0 0 0 f ( n ) = n = 1 ∑ 1 0 0 0 d 0 n + n = 1 ∑ 1 0 0 0 d 1 n + n = 1 ∑ 1 0 0 0 d 2 n + n = 1 ∑ 1 0 0 0 d 3 n
Therefore, n = 1 ∑ 1 0 0 0 f ( n ) = 4 5 0 0 + 4 5 0 0 + 4 5 0 0 + 1 = 1 3 5 0 1 ⟹ None of the other choices.