4697: Robbers' watch 强盗手表

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:15 通过:13

题目描述

劫匪袭击了格尔达的出租车,他们非常成功地掩护了王国警察。为了使捕捉它们的目标更加困难,他们使用自己的手表。

首先,由于他们知道王国警察不擅长数学,劫匪使用以7为基数的位置数字系统。其次,它们以 n 小时划分一天,以 m 分钟为单位划分每小时。每个劫匪的个人手表分为两部分:第一部分具有显示 0 到 n - 1 的任何整数所需的最小位置数,而第二部分具有显示从 0 到 m - 1 的任何整数所需的最小位置数。最后,如果可以使用比此手表更少的基数 7 位来显示小时或分钟的某些值,则会在符号的开头添加所需的零数。

请注意,要显示手表的数字 0 部分,至少需要一个位置。

小强盗想知道时间的时刻数(小时和分钟的特定值),以便手表上显示的所有数字都是不同的。帮她算这个数字。



Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n-1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m-1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1≤n,m≤109)− the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation− the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0:1), (0:2), (1:0), (1:2).
In the second sample, possible pairs are: (02:1), (03:1), (04:1), (05:1), (06:1).

输入格式

输入的第一行包含两个整数,以十进制表示法 n 和 m 给出 (≤ N, m ≤ 109) — 一天中的小时数和一小时中的分钟数。

输出格式

以十进制表示法打印一个整数 — 小时和分钟的不同对的数量,以便手表上显示的所有数字都是不同的。

输入样例 复制

2 3

输出样例 复制

4

数据范围与提示

在第一个示例中,可能的对是:(0:1)(01),(0:2)(02),(1:0)(10),(1:2)(12).

在第二个示例中,可能的对是:(02:1)(021),(03:1)(031),(04:1)(041),(05:1)(051),(06:1)(061).