CF685A.Robbers' watch

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

抢劫者袭击了格尔达的马车,他们非常擅长躲避王国警察的追捕。为了使警察抓捕他们的难度进一步加大,他们使用自己特制的手表。

首先,由于抢劫者知道王国警察不擅长数学,他们采用以 77 为底的进位制(即七进制)。其次,他们将一天划分为 nn 小时,每小时划分为 mm 分钟。每位抢劫者的手表分为两部分:第一部分用于显示小时数,其位数取能表示从 00 到 n−1n-1 中任意整数所需的最小位数;第二部分用于显示分钟数,其位数取能表示从 00 到 m−1m-1 中任意整数所需的最小位数。最后,若某个小时数或分钟数在七进制下所需位数少于手表对应部分的位数,则需在该数的七进制表示前补足相应个数的零(即左补零)。

注意:为表示数字 00,手表对应部分至少需要一位。

一名小抢劫者想知道:有多少个不同的时刻(即特定的小时与分钟组合),使得手表上显示的所有数字互不相同?请帮她计算这个数目。

输入格式

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.

输入的第一行包含两个十进制表示的整数 nn 和 mm(1 ≤ n, m ≤ 1091 \leq n, m \leq 10^9),分别表示一天中的小时数和一小时中的分钟数。

输出格式

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.

以十进制输出一个整数——满足手表上显示的所有数字互不相同的小时与分钟的不同配对数量。

输入输出样例

  • 输入#1

    2 3

    输出#1

    4
  • 输入#2

    8 2

    输出#2

    5

说明/提示

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

在第一个样例中,可能的数对为:(0: 1)(0: 1)、(0: 2)(0: 2)、(1: 0)(1: 0)、(1: 2)(1: 2)。

在第二个样例中,可能的数对为:(02: 1)(02: 1)、(03: 1)(03: 1)、(04: 1)(04: 1)、(05: 1)(05: 1)、(06: 1)(06: 1)。

输入解题思路,AI测评打分。不知道怎么写?

首页