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分钟  手表为7进制数表示时间,每一位的数字不能重复 问能表示多少种组合的时间

题解:首先判断 若要表示n小时m分钟需要多少位,若超过7位则输出0

否则 分别判断n*m的组合 是否满足条件 (缺位的情况下补零)

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
int len1,len2;
bool fun(int aa,int bb)
{
int sa[];
int sb[];
memset(sa,,sizeof(sa));
memset(sb,,sizeof(sb));
int len3=len1;int len4=len2;
while()
{
sa[len3--]=aa%;
aa/=;
if(aa==)
break;
}
while(len3>)
sa[len3--]=;
while()
{
sb[len4--]=bb%;
bb/=;
if(bb==)
break;
}
while(len4>)
sb[len4--]=;
for(int i=;i<=len1;i++)
for(int j=i+;j<=len1;j++)
if(sa[i]==sa[j])
return false;
for(int i=;i<=len2;i++)
for(int j=i+;j<=len2;j++)
if(sb[i]==sb[j])
return false;
for(int i=;i<=len1;i++)
for(int j=;j<=len2;j++)
{
if(sa[i]==sb[j])
return false;
}
return true;
}
int main()
{
scanf("%d %d",&n,&m);
int q1=n-,q2=m-;
len1=;len2=;
int ans=;
while()
{
q1/=;
len1++;
if(q1==)
break;
}
while()
{
q2/=;
len2++;
if(q2==)
break;
}
if(len1+len2>)
printf("0\n");
else{
for(int i=;i<n;i++)
for(int j=;j<m;j++)
{
if(fun(i,j))
ans++;
}
cout<<ans<<endl;
} return ;
}

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

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

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

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

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

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

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

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

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

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

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

  9. Codeforces Round #359(div 2)

    A:= v = B:^ w ^ C:一天n个小时,一个小时m分(n,m十进制),一个手表有两部分,左边表示时,右边表示分,但都是7进制,而且手表上最多只能有7个数字且数字不能重复,现在要你算出能正确表 ...

  10. Codeforces Round #359 (Div. 2) D. Kay and Snowflake 树DP

    D. Kay and Snowflake     After the piece of a devilish mirror hit the Kay's eye, he is no longer int ...

随机推荐

  1. php-5.6.26源代码 - opcode列表

    文件 php-5.6.26/Zend/zend_vm_opcodes.h #ifndef ZEND_VM_OPCODES_H #define ZEND_VM_OPCODES_H BEGIN_EXTER ...

  2. 430. Flatten a Multilevel Doubly Linked List

    /* // Definition for a Node. class Node { public: int val = NULL; Node* prev = NULL; Node* next = NU ...

  3. is 和 == 的区别,utf和gbk的转换,join用法

    is 和 == 的区别 # is 比较的是内存地址 # == 比较的是值 a = 'alex' b = 'alex' #int,str(小数据池)会被缓存,为了节约内存 print(id(a),id( ...

  4. 15.4,redis不重启,切换RDB备份到AOF备份

      确保redis版本在2.2以上 [root@pyyuc /data ::]#redis-server -v Redis server v= sha=: malloc=jemalloc- bits= ...

  5. Android 做项目总结

    1.base 2.跳转可以用uihelper 3.activity和处理逻辑分开 4.userhelper保存管理用户登录信息 5.验证输入框的时候,接受的参数不要是String ,而是Edittex ...

  6. java.sql.SQLException: Field 'id' doesn't have a default value异常

    在做mybatis插入的时候报了这个错误,百度了下,貌似是因为这个健没有设置值且不是自增类型的. java.sql.SQLException: Field 'id' doesn't have a de ...

  7. wireshark 安装

    #yum install wireshark 安装完毕后 whereis wireshark 找不到可执行程序 /bin /sbin /usr/bin /usr/sbin下均没有. 实际上wiresh ...

  8. JavaSE总结--多线程

    进程: 进程之间内存隔离,内存不共享. 线程: 可以共享内存. 每个线程都是一个栈. 多线程的好处: 1)防止程序阻塞. wait与notify的区别: 针对等待队列而言. wait:进入等待队列.必 ...

  9. BitLocker:如何启用网络解锁

    TechNet 库Windows ServerWindows Server 2012 R2 和 Windows Server 2012服务器角色和技术安全和保护BitLockerBitLocker 中 ...

  10. APP测试用例要考虑的一些方面

    安装与卸载:●应用是否可以在IOS不同系统版本或android不同系统版本上安装(有的系统版本过低,应用不能适配)●软件安装后是否可以正常运行,安装后的文件夹及文件是否可以写到指定的目录里.●安装过程 ...