201420: [AtCoder]ARC142 A - Reverse and Minimize

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

Description

Score : $300$ points

Problem Statement

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$

Output

Print the answer.


Sample Input 1

1420 142

Sample Output 1

3

Three integers $x=142$, $241$, and $1420$ satisfy $1 \leq x \leq 1420$ and $f(x)=142$.


Sample Input 2

1419 142

Sample Output 2

2

Sample Input 3

6 19

Sample Output 3

0

Input

题意翻译

在 $x$ 中,可以执行 $0$ 次或多次以下操作: 将 $x$ 左右反转得到的整数为 $x'$,将 $x$ 替换为 $x'$,删除 $x$ 开头的 $0$。 计算操作后 $x$ 的最小值,这个值被定义为 $f(x)$。 你需要求出 $1\le x\le N$ 且满足 $f(x)=K$ 的整数 $x$ 的个数。

加入题单

上一题 下一题 算法标签: