Codeforces Round 359 (Div. 1)
A
Robbers' watch
Codeforces
1700
原题
←B →
翻译中…

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* ≤ 10^{9}$) — 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.

翻译中…

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)$.

翻译中…

样例

Input #1
2 3
Output #1
4
InputCopy OutputCopy
Input #2
8 2
Output #2
5
InputCopy OutputCopy
题目信息
题号
685A
时间限制
2 s
内存限制
256 MB
标签
暴力
组合数学
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。