201270: [AtCoder]ARC127 A - Leading 1s

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

For an integer $x$, let $f(x)$ be the number of leading ones in the decimal notation of $x$. For example, we have $f(1)=1,f(2)=0,f(10)=1,f(11)=2,f(101)=1$.

Given an integer $N$, find $f(1)+f(2)+\cdots+f(N)$.

Constraints

  • $1 \leq N \leq 10^{15}$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$

Output

Print the answer.


Sample Input 1

11

Sample Output 1

4

We have $f(2)=f(3)=\cdots =f(9)=0$. The answer is $f(1)+f(10)+f(11)=4$.


Sample Input 2

120

Sample Output 2

44

Sample Input 3

987654321

Sample Output 3

123456789

Input

题意翻译

当用十进制表示整数 $x$ 时,最高位开始连续的1的个数用 $f[x]$ 表示,例如 $f[1]=1$ , $f[2]=0$ ,$f[10]=1$ ,$f[11]=2$ , $f[101]=1$ 。 给出了整数N,求 $\sum_{n=1}^i f[i]$ 。 - $n \le 10^{15}$

加入题单

上一题 下一题 算法标签: