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

链接:http://codeforces.com/contest/686/problem/C晚上做的时候想到了位数大于7的时候,输出0,但就是没想到之后暴力就可以解了 = =
还有,这代码中的判断条件想法也比较好,开一个used的vector,之后判断每个数变成7进制之后的各个数出现的次数,如果其中最大的小于等于1,那么就可行。这种想法真的很好,写着也简洁,需要学习。
#include <bits/stdc++.h>
using namespace std; int main()
{
//这是加速cin的,网上说用完之后,速度和scanf差不多
iostream::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr); //size_t 相当于无符号int
size_t n,m;
cin>>n>>m;
size_t len1=,len2=;
for (size_t a=;a<n;a*=)
len1++;
for (size_t b=;b<m;b*=)
len2++; size_t ans=;
if (len1+len2<=)
for (size_t i=;i<n;i++)
for (size_t j=;j<m;j++)
{
vector<size_t> used(,);
for (size_t a=i,k=;k<len1;a/=,k++)
{
used[a%]+=;
}
for (size_t b=j,k=;k<len2;k++,b/=)
{
used[b%]+=;
} //max_element 返回迭代器,所以要解引用
if (*max_element(used.begin(),used.end())<=)
ans++;
}
cout<<ans<<endl; return ;
}

Codeforces Round #359 (Div. 2)C - Robbers' watch的更多相关文章

  1. Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力

    A. Robbers' watch 题目连接: http://www.codeforces.com/contest/685/problem/A Description Robbers, who att ...

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

  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. linux下遍历目录(转-在于思考)

    遍历目录的主要思想 由于目录就是一颗树,所以遍历目录就转换为遍历一棵树.谈到树的遍历就再熟悉不过了,有树的前序.层次和后序遍历,我使用的是前序遍历,后序遍历和前序遍历本质上一样,而层次遍历要比前两个麻 ...

  2. HDU5934 Bomb(2016杭州CCPC第二题)(强连通缩点)

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  3. poj1094 拓扑序

    题意:现在有多个大写字母(不一定连续),给出字母之间的大小关系,问到第几个关系时就能判断有唯一大小排序或出现矛盾,或是有多个合理排序,若有唯一排序,则输出它. 拓扑序,只不过坑爹的是如果关系处理到一半 ...

  4. MAC 如何修改PATH

    http://hathaway.cc/post/69201163472/how-to-edit-your-path-environment-variables-on-mac

  5. STM32的Cortex-M3核与ARM7有何区别?哪个性能更强?

  6. <初级程序员> git 的初级使用

    作为程序员,Git 是一个很好的代码管理工具.Git 是一个版本控制系统,主要的作用就是记录代码的修改过程,有效的追踪文件的变化.当代码出现错误的时候可以很容易的恢复到之前的状态,不管对于个人开发还是 ...

  7. Linux下串口与工业协议的开发

    1.串口通信原理 串口通信定义 串口通信:数据的串行传送方式.串口通信可分为同步通信与异步通信. 同步通信:按照软件识别同步字符来实现数据的发送和接收. 将许多字符组成一个信息组进行发送 要求发送时钟 ...

  8. 利用CSS的@font-face属性 在网页中嵌入字体

    字体使用是网页设计中不可或缺的一部分.网页是文字的载体,我们希望在网页中使用某一特定字体,但是该字体并非主流操作系统的内置字体,这样用户在浏览页面的时候就有可能看不到真实的设计. 美工设计师最常做的办 ...

  9. java多线程:并发包中ReentrantReadWriteLock读写锁的锁降级模板

    写锁降级为读锁,但读锁不可升级或降级为写锁. 锁降级是为了让当前线程感知到数据的变化. //读写锁 private ReentrantReadWriteLock lock=new ReentrantR ...

  10. css_三种引入方法

    CSS是英文Cascading Style Sheets的缩写,称为层叠样式表,用于对页面进行美化. 详请:http://www.w3school.com.cn/h.asp 其存在方式有三种:元素内联 ...