题目描述
Problem Description
For a positive integer $x$, let $rev(x)$ denote the integer obtained by reversing the digits of $x$ when $x$ is written in base 10. For example, $rev(123)=321$, $rev(90)=9$, and $rev(5)=5$.
You are given positive integers $N$ and $M$. Find the number of pairs of integers $(x, y)$ such that $1 \leq x \leq N$ and $1 \leq y \leq M$, and starting from $(x, y)$, the following sequence of operations can be performed infinitely:
- If either $x$ or $y$ is $0$, the process ends.
- If $x < y$, replace $x$ with $rev(x)$; otherwise, replace $y$ with $rev(y)$.
- After the above operation, if $x < y$, replace $y$ with $y - x$; otherwise, replace $x$ with $x - y$.
Input Format
The input is given from the standard input in the following format:
$N$ $M$
Output Format
Output the number of pairs $(x, y)$ such that starting from $(x, y)$, the operations can be performed infinitely.
Sample Input and Output
Sample Input #1
13 13
Sample Output #1
1
Sample Input #2
20 30
Sample Output #2
28
Sample Input #3
314 159
Sample Output #3
1915
Notes/Hints
Constraints
- $1 \leq N, M \leq 999$
- All inputs are integers.
Sample Explanation 1
The pair $(13, 13)$ satisfies the condition. Specifically, the operations proceed as $(13, 13) \rightarrow (13, 18) \rightarrow (13, 18) \rightarrow \ldots$ and continue indefinitely.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分