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. linux更换shell外壳zsh

    linux-外壳内核与shell的关系 内核处于外壳之中,通过外壳与shell(命令行)交互 外壳可以更换 ############################################## ...

  2. centos7.3下curl支持https协议

    1 由于自己的curl是默认安装的,查看了下 不支持https协议 [root@izwz90bp6do7s3cr45cw6az ~]# curl --version curl (x86_64-redh ...

  3. jpa-入门级测试

  4. 3.Web项目中使用Log4j实例

    转自:https://blog.csdn.net/luohai859/article/details/52250807 上面代码描述了Log4j的简单应用,其实使用Log4j也就是这样简单方便.当然除 ...

  5. mysql的时区错误的解决办法

    十二月 02, 2018 9:16:19 下午 com.mchange.v2.resourcepool.BasicResourcePool 警告: Having failed to acquire a ...

  6. spring-boot+quartz的CRUD动态任务管理系统

    版权声明:作者: 小柒 出处: https://blog.52itstyle.com 分享是快乐的,也见证了个人成长历程,文章大多都是工作经验总结以及平时学习积累,基于自身认知不足之处在所难免,也请大 ...

  7. 使用jquery.more.js来实现点击底部更多后, 底部加载出新的数据

    <div class="bus-nav-bar ft12"> <div class="navt bor-r-c pos-rel {if $int == ...

  8. c++实现一个比较两个string类型的版本号的小demo

    在软件实现更新模块的时候,有可能会判断一下服务器上的版本的版本号和本地版本的版本号. 下面有类似这样形式的版本号:string str = "0.0.0.1"; 分析一下可以看出, ...

  9. v​n​c​服​务​​安​装​与配置

    一.Redhat上VNC Server配置 本文以当前Linux系统未安装VNC服务器为基本,如果已安装请跳过第1节! 前提: 1.安装 TigerVNC Server # yum search ti ...

  10. js中常见的内置对象

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...