A. Robbers' watch
time limit per test:

2 seconds

memory limit per test:

256 megabytes

input:

standard input

output:

standard output

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

题目链接:http://codeforces.com/problemset/problem/685/A


题意:一天有n个小时,每小时有m分钟。一个7进制表示的时钟一天内有几次钟表上出现的数字均不相同。

思路:钟表上面一共有len位数。当len>7时直接不可能每位数字均不相同。只考虑len<=7的情况。用0,1,2,3,4,5,6里面的len位进行全排列。在选前x(1<=x<len)位作为小时hh,len-x位作为分钟mm。当hh<n&&mm<m时并且没有出现过,答案+1。

代码:

#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int getnum(int x)
{
int gg=;
if(x==)
return ;
while(x)
{
x/=;
gg++;
}
return gg;
}
int sign[];
int num[];
map< int, map<int,int> >gg;
int DFS(int x,int len)
{
int i,j;
if(x==len)
{
/*
for(i=1;i<=len;i++)
cout<<num[i]<<" ";
cout<<endl;
*/
for(i=; i<len; i++)
{
int hh=,mm=;
int base=;
for(j=i; j>=; j--)
{
hh+=num[j]*base;
base*=;
}
base=;
for(j=len; j>i; j--)
{
mm+=num[j]*base;
base*=;
}
//cout<<"hh="<<hh<<" mm="<<mm<<endl;
if(hh<=n&&mm<=m)
{
if(gg[hh][mm]==) ans++;
gg[hh][mm]=;
}
if(hh>n) break;
}
}
for(i=; i<; i++)
{
if(sign[i]==)
{
num[x+]=i;
sign[i]=;
DFS(x+,len);
sign[i]=;
}
}
}
int main()
{
int i;
scanf("%d%d",&n,&m);
n--;
m--;
int len=getnum(n)+getnum(m);
if(len>) cout<<""<<endl;
else
{
memset(sign,,sizeof(sign));
memset(num,,sizeof(num));
ans=;
DFS(,len);
cout<<ans<<endl;
}
return ;
}

Codeforces 658A. Robbers' watch 模拟的更多相关文章

  1. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  2. Codeforces 626A Robot Sequence(模拟)

    A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  3. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  4. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  5. Codeforces 704A Thor 队列模拟

    题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...

  6. Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)

    大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...

  7. Codeforces 691C. Exponential notation 模拟题

    C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...

  8. Codeforces 438D (今日gg模拟第二题) | 线段树 考察时间复杂度的计算 -_-|||

    Codeforces 438D The Child and Sequence 给出一个序列,进行如下三种操作: 区间求和 区间每个数模x 单点修改 如果没有第二个操作的话,就是一棵简单的线段树.那么如 ...

  9. CodeForces 2A - Winner(模拟)

    题目链接:http://codeforces.com/problemset/problem/2/A A. Winner time limit per test 1 second memory limi ...

随机推荐

  1. 开发组件:REST API

    REST API 最佳入门指南 https://blog.csdn.net/px01ih8/article/details/78674685

  2. HTML+CSS实现页面

    使用HTML和CSS实现以下页面: 抽屉首页 个人博客首页 小米官网首页 登录注册页面 一.抽屉首页 1.实现目标:https://dig.chouti.com/ 2.代码: HTML: <!- ...

  3. centos7.3安装zend guard loader3.3 for php5.6

    1 下载zend guard loader 到这里选择自己的系统版本  我选择的64位 for php5.6.3  linux http://www.zend.com/en/products/load ...

  4. 理解无偏估计(unbiased estimation)

    判断一个估计量“好坏”,至少可以从以下三个方面来考虑: 无偏估计 有效性 一致性 参考内容: 如何理解无偏估计量?https://www.matongxue.com/madocs/808.html 衡 ...

  5. sun 证书问题解决

    1.下载的需要的证书: sudo ./$JAVA_HOME/jre/bin/keytool -import -alias WOSt03 -keystore $JAVA_HOME/jre/lib/sec ...

  6. 一个NPOI导出到excel文件的范例记录

    '使用NPOI写入新创建的excel文件,导出文件: Private Sub Sub_WriteXls() Dim XlsBook As XSSFWorkbook Dim XlsSheet As XS ...

  7. 3.为什么要使用struts2代替struts1.x

    转自:https://blog.csdn.net/li15365002374/article/details/9166431?utm_source=blogxgwz1 (1)struts2的execu ...

  8. 在 WampServer 上手工安装 PHP 的多个版本

    手工安装新版本的PHP,只需以下步骤: 下载要安装的PHP版本.既然是用WampServer,那当然是下载Window版本的ZIP包啦:http://windows.php.net.解压到 Wamp的 ...

  9. eclipse xDoclet错误

    转载: http://blog.csdn.net/lovelongjun/article/details/53485773 Missing library: xdoclet-1.2.1.jar. Se ...

  10. python contextmananger装饰器与with

    如果想自定义一个类或者函数使用with语句,除了在类中自己定义__enter__()方法和__exit__()方法外,还可以使用contextmananger装饰器. contextmananger装 ...