Reverse and Minimize

AtCoder
IDarc142_a
Time2000ms
Memory256MB
Difficulty
For a positive integer $x$, let $f(x)$ be the answer to the question below. > The following operation on $x$ can be performed zero or more times. > > * Let $x'$ be the integer obtained by reversing the decimal notation of $x$. Then, replace $x$ with $x'$. If $x$ now has one or more leading zeros, delete them so that it begins with a non-zero digit. > > For example, from $x=1420$, you get $x=241$ after one operation, $x=142$ after two operations, and $x=241$ after three operations. > Find the minimum possible value of $x$ after operations. Find the number of integers $x$ such that $1 \leq x \leq N$ and $f(x)=K$. ## Constraints * $1 \leq N,K \leq 10^{12}$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $K$ [samples]
Samples
Input #1
1420 142
Output #1
3

Three integers $x=142$, $241$, and $1420$ satisfy $1 \leq x \leq 1420$ and $f(x)=142$.
Input #2
1419 142
Output #2
2
Input #3
6 19
Output #3
0
API Response (JSON)
{
  "problem": {
    "name": "Reverse and Minimize",
    "description": {
      "content": "For a positive integer $x$, let $f(x)$ be the answer to the question below. > The following operation on $x$ can be performed zero or more times. >  > *   Let $x'$ be the integer obtained by reversin",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc142_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "For a positive integer $x$, let $f(x)$ be the answer to the question below.\n\n> The following operation on $x$ can be performed zero or more times.\n> \n> *   Let $x'$ be the integer obtained by reversin...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments