Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input
The first line contains integer n (1 ≤ n ≤ 109) — the number of books in the library.
Output
Print the number of digits needed to number all the books.
Examples
Input
13Output
17Input
4Output
4Note
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
AC代码(做的时候卡了好长时间,就是假如他是三位数我们减去一位的数字的个数
减去两位的数字的个数然后剩下的是三位数的个数)
#include <iostream> #include <bits/stdc++.h> using namespace std; int main() { int i; long long s, m,a[20], sm; a[0] = 0, a[1] = 9, a[2] = 90, a[3] = 900, a[4] = 9000, a[5] = 90000; a[6] = 900000, a[7] = 9000000, a[8] = 90000000, a[9] = 900000000; while(cin>>s) { sm = 0; int h = 0; m = s; while(m>0) { m = m/10; h++; } for(i = 1;i<h;i++) { sm = sm+a[i]*i; s = s-a[i]; } sm = sm + s*h; cout<<sm<<endl; } return 0; }