Leading 1s

AtCoder
IDarc127_a
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
11
Output #1
4

We have $f(2)=f(3)=\cdots =f(9)=0$. The answer is $f(1)+f(10)+f(11)=4$.
Input #2
120
Output #2
44
Input #3
987654321
Output #3
123456789
API Response (JSON)
{
  "problem": {
    "name": "Leading 1s",
    "description": {
      "content": "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",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc127_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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$.\nGiven an integer $N$, find $f(1)+f(2)+\\cdots...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments