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. 放课后的约定 by:S_H_Y

    题目背景 十年.十年前.天空的蔚蓝,云彩的舒软.我,怎么会认识你.洁白的,洁白的,十年前.我无法忘却.终究是小时候的约定.记忆被困在冻土里,有时我不认识那天的我.难道一切,都锁在心里面了吗? 题目描述 ...

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

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

  3. Android—菜单

    layout文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...

  4. 【P1813】8的倍数

    容斥原理,居然没想到……要补一下数论了 原题: 小x最近对数字8很感兴趣,有8进制,2008奥运会之类的.现在小x想知道,在[x,y]区间里,有多少个数能被8整除.小y觉得题目太简单,于是给出n个其他 ...

  5. GOOGLE的专业使用方法(转)

    搜索引擎命令大全! 1.双引号 把搜索词放在双引号中,代表完全匹配搜索,也就是说搜索结果返回的页面包含双引号中出现的所有的词,连顺序也必须完全匹配.bd和Google 都支持这个指令.例如搜索: “s ...

  6. 图片Exif信息

    Exif文件格式简述链接:https://www.zhihu.com/question/23727439/answer/25467748 可交换图像文件常被简称为Exif(Exchangeable i ...

  7. 在div中设置文字与内部div垂直居中

    要实现如图一所示的结果: html代码如下: <!DOCTYPE html> <html> <head lang="zh"> <meta ...

  8. Linux信号量详解

    1.什么是信号量信号量是一种特殊的变量,访问具有原子性.只允许对它进行两个操作:1)等待信号量当信号量值为0时,程序等待:当信号量值大于0时,信号量减1,程序继续运行.2)发送信号量将信号量值加1. ...

  9. 在Hyper-V虚拟机中使用Wi-Fi上网

    笔记本配置了一块以太网卡和一块无线网卡.由于平时常用Wi-Fi上网,偶然发现Hyper-V虚拟机默认不能使用宿主系统的无线网卡上网,据说是出于安全方面的考虑.后来参考"Using Wirel ...

  10. 010. 使用.net框架提供的属性

    C#允许在类和类成员上声明特性(类), 可在运行时解释类和类的成员. 这个特性也称为属性, 使用Attribute.下面演示如何使用.net框架提供的属性. using System; using S ...