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

题意:给你一个表,问小于n的小时和小于m的分钟用七进制表示,所有数字都不相同的个数,不足的位置用0补;

思路:根据鸽巢,首先最多7个数不同,用全排列next_mutation解决,一个小坑就是7为1位数,即判断位数的时候要小心

#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e3+,M=1e6+,inf=1e9+;
int getnum(int x)
{
int ans=;
if(x==)
return ;
while(x)
{
x/=;
ans++;
}
return ans;
}
int a[]={,,,,,,};
pair<int,int>p;
map<pair<int,int>,int>m;
int check(int pos,int len,int x,int y)
{
int base=;
int num=;
for(int i=pos-;i>=;i--)
{
num+=a[i]*base;
base*=;
}
int shu=;
base=;
for(int i=len-;i>=pos;i--)
{
shu+=a[i]*base;
base*=;
}
if(num<=x&&shu<=y)
{
if(m[make_pair(num,shu)])
return ;
else
{
m[make_pair(num,shu)]=;
return ;
}
}
return ;
}
int main()
{
int x,y,z,i,t;
scanf("%d%d",&x,&y);
x--;
y--;
z=getnum(x)+getnum(y);
if(z>)
printf("0\n");
else
{
int ans=;
do
{
for(i=;i<z;i++)
if(check(i,z,x,y))
{
ans++;
}
}while(next_permutation(a,a+));
printf("%d\n",ans);
}
return ;
}

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

  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

    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 (暴力DFS)

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

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

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

  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. 使用nginx搭建文件下载服务器

    搭建一个文件服务器的方式有很多,本文介绍笔者曾经用过的两种: 使用nginx 使用java服务,通过controller提供 一.使用nginx搭建 在nginx.conf中直接配置server即可, ...

  2. 003-linux基本目录介绍

    一.文件系统的类型 LINUX有四种基本文件系统类型:普通文件.目录文件.连接文件和特殊文件,可用file命令来识别. 普通文件:如文本文件.C语言元代码.SHELL脚本.二进制的可执行文件等,可用c ...

  3. 《FLASH PROGRAMMING 那些事》总结

    注明来自 http://www.ssdfans.com/?p=5589 以MLC为例: 对FGF(Floating Gate Flash)技术的,MLC programming一般分两步走:先prog ...

  4. 记录:正确率、召回率、F值

    因为不理解召回率,所以去查看了一些资料.特此记录一下自己的理解,以便以后查看. 说明 正确率=查出来正确的样本数/全部查出来的样本数 (也可以理解为查准率) 召回率=查出来正确的样本数/数据集里全部正 ...

  5. LDA算法里面Dirichlet分布的两个参数alpha和beta怎样确定?

    本文参考自:https://www.zhihu.com/question/21692336/answer/19387415   方法一: alpha 是 选择为 50/ k, 其中k是你选择的topi ...

  6. PL/SQL编程—存储过程

    SQL> create or replace procedure sp_pro3(name_in varchar2,id_in varchar2) is begin update mytest ...

  7. 解决NodeJS+Express模块的跨域访问控制问题:Access-Control-Allow-Origin

    在一个项目上想用NodeJS,在前端的js(http://localhost/xxx)中ajax访问后端RestAPI(http://localhost:3000/….)时(Chrome)报错: XM ...

  8. [leetcode刷题笔记]Implement Trie (Prefix Tree)

    题目链接 一A,开森- ac代码: class TrieNode { // Initialize your data structure here. char content; boolean isW ...

  9. SQL执行并返回执行前/后结果

    SQLServer: 1.插入数据,并返回插入的数据: INSERT INTO TestTB(Province,City) output inserted.Province, inserted.Cit ...

  10. javascript 面向对象 new 关键字 原型链 构造函数

    JavaScript面向对象JavaScript 语言使用构造函数(constructor)作为对象的模板.所谓"构造函数",就是专门用来生成实例对象的函数.它就是对象的模板,描述 ...