시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 108 | 69 | 57 | 82.609% |
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
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]
15
66
9935125239801570
714619374344308434
1000
13501
83
678