[BOJ 13245] Sum of digits
View as PDF
Submit solution
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text
Points:
3
Time limit:
2.0s
Memory limit:
512M
Problem types
Allowed languages
It is easy to compute the sum of the numbers in the sequence from 0 to n with the formula n(n+1)/2. That is: 0 + 1 + 2 + .... + n = n(n+1)/2</p>
This problem is a bit harder: what about the sum of the digits in the sequence [0, 1, ..., n]?
Write a program that computes the sum of the digits that can be found when counting from 0 to n.
For n = 15 we want to sum the digits that appear in the sequence [0, 1, 2, ..., 14, 15].
The result is: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 0 +1 + 1 + 1 + 2 + 1 + 3 + 1 + 4 + 1 + 5 = 66
입력 형식
A single line with an integer n (1 ≤ n ≤ 1016)
출력 형식
A single line with the sum of digits in the sequence [0, 1, ..., n-1, n]
예제 입력 1
15
예제 출력 1
66
예제 입력 2
9935125239801570
예제 출력 2
714619374344308434
예제 입력 3
1000
예제 출력 3
13501
예제 입력 4
83
예제 출력 4
678
Comments