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.
InputThe first line contains integer n (1 ≤ n ≤ 109) — the number of books in the library.
Print the number of digits needed to number all the books.
13
17
4
4
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.
题意:为1-n之中有多少个数字。
题解:找规律。
#include<stdio.h>
#include<string.h>
int main()
{
long long i,n;
scanf("%lld",&n);
if(n<10)
{
i=n;
}
else if(n>9&&n<100)
{
i=2*n-9;
}
else if(n>99&&n<1000)
{
i=3*n-108;
}
else if(n>999&&n<10000)
{
i=4*n-1107;
}
else if(n>9999&&n<100000)
{
i=5*n-11106;
}
else if(n>99999&&n<1000000)
{
i=6*n-111105;
}
else if(n>999999&&n<10000000)
{
i=7*n-1111104;
}
else if(n>9999999&&n<100000000)
{
i=n*8-11111103;
}
else if(n>99999999&&n<1000000000)
{
i=9*n-111111102;
}
else if(n==1000000000)
{
i=10*n-1111111101;
}
printf("%lld",i);
return 0;
}