A. Robbers' watch

题目连接:

http://www.codeforces.com/contest/685/problem/A

Description

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.

Sample Input

2 3

Sample Output

4

Hint

题意

有n个小时,m分钟,7进制时间,问你这一天一共有多少个时间,他的数字都不相同。

题解:

差点就写数位dp了……

首先,如果这个时钟的数字超过了7位,那么肯定有相同的,根据鸽巢原理很容易判断出来

然后小于七位的,实际上数字就很少了,我们直接暴力就好了……

然后这道题就完了。

代码

#include<bits/stdc++.h>
using namespace std; int num[10],ans;
void check(int x,int y,int n,int m)
{
for(int i=0;i<10;i++)num[i]=0;
if(!n)num[0]++;
if(!m)num[0]++;
while(n){
num[x%7]++;
x/=7;
n/=7;
}
while(m){
num[y%7]++;
y/=7;
m/=7;
}
for(int i=0;i<10;i++)
if(num[i]>1)return;
ans++;
}
int n,m;
int main()
{
scanf("%d%d",&n,&m);
if(1ll*n*m>1e7){
puts("0");
return 0;
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
check(i,j,n-1,m-1);
cout<<ans<<endl;
}

Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力的更多相关文章

  1. Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)

    题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...

  2. Codeforces Round #359 (Div. 2)C - Robbers' watch

    C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  3. Codeforces Round #359 (Div. 2) C. Robbers' watch 搜索

    题目链接:http://codeforces.com/contest/686/problem/C题目大意:给你两个十进制的数n和m,选一个范围在[0,n)的整数a,选一个范围在[0,m)的整数b,要求 ...

  4. Codeforces Round #359 (Div. 2) C. Robbers' watch 鸽巢+stl

    C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. Codeforces Round #359 (Div. 1)

    A http://codeforces.com/contest/685/standings 题意:给你n和m,找出(a,b)的对数,其中a满足要求:0<=a<n,a的7进制的位数和n-1的 ...

  6. Codeforces Round #359 (Div. 1) B. Kay and Snowflake dfs

    B. Kay and Snowflake 题目连接: http://www.codeforces.com/contest/685/problem/B Description After the pie ...

  7. Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo 水题

    B. Little Robber Girl's Zoo 题目连接: http://www.codeforces.com/contest/686/problem/B Description Little ...

  8. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  9. Codeforces Round #359 (Div. 2) C

    C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

随机推荐

  1. 邮件伪造测试-Swaks

    1. 前言 在kali中自带一个邮件伪造工具Swaks,工具项目主页为 http://jetmore.org/john/code/swaks 2.基本用法: swaks --to --from --e ...

  2. 理解mipi协议【转】

    转自:http://blog.csdn.net/wanglining1987/article/details/50202615 完成mipi信号通道分配后,需要生成与物理层对接的时序.同步信号: MI ...

  3. 通过PDB文件实现非嵌入式的c++反射

    上一篇blog我阐述了一种实现非嵌入式的反射的基本思路.相比于通过宏和模板实现,这种非嵌入的反射的优点是不需要写额外的代码来记录meta信息. 首先,为了在c++中实现反射系统,我认为需要解决以下两个 ...

  4. OpenStack 监控解决方案

    正如你们看到的那样,到目前为止(OpenStack Kilo),OpenStack自己的监控组件Telemetry并不是完美, 获取的监控数据以及制作出来的图表有时候让人匪夷所思,因其重点并不是监控而 ...

  5. Django集成Xadmin list index out of range报错解决方案

    return self.render(context) File "C:\Python36\lib\site-packages\django\template\defaulttags.py& ...

  6. unity3d 材质概述 ---- shader

    学习笔记:      材质概述:  物体呈现在我们前面除了形体外,还包括“固有颜色”和“质地”(质感与光学性质).固有颜色让物体的表面看起来是什么颜色,而质感决定了该物质是使用什么材质的.在三维建模软 ...

  7. 详解MySQL大表优化方案

    单表优化 除非单表数据未来会一直不断上涨,否则不要一开始就考虑拆分,拆分会带来逻辑.部署.运维的各种复杂度,一般以整型值为主的表在千万级以下,字符串为主的表在五百万以下是没有太大问题的.而事实上很多时 ...

  8. [java笔记]父类设计法则

    1.父类通常情况下都设计为抽象类或接口,其中优先考虑接口,如接口不能满足才考虑抽象类. 2.一个具体的类尽可能不去继承另一个具体类,这样的好处是无需检查对象是否为父类的对象.

  9. IntelliJ IDEA 把Json字符串 增加到IDE里 用windows记事本 能自动转换(自动增加转义字符)

  10. MySQL学习笔记:definer与sql security

    在以下例子中,出现definer于sql security invoker,导致不解,遂学习一翻. # 创建存储过程 DELIMITER $$ CREATE DEFINER = Hider@local ...