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 ;
}

最新文章

  1. iOS UIPageViewController缺陷
  2. Linux 下MySql 重置密码
  3. BZOJ2190 [SDOI2008]仪仗队(欧拉函数)
  4. Hashtable、Dictionary和List 谁效率更高
  5. 函数调用和inline作用
  6. PowerDesigner 为sql生成凝视
  7. 简单的线性回归问题-TensorFlow+MATLAB&#183;
  8. MySQL之增_insert-replace
  9. NHibernate教程(8)--巧用组件
  10. 系列博文-Three.js入门指南(张雯莉)-照相机
  11. Android 自定义控件 轻松实现360软件详情页
  12. Spring Cloud 组件 —— eureka
  13. ____利用C#特性Attribute完成对sql语句的拼接
  14. 利用 ffmpeg 的 maskedmerge 滤镜, 从视频中提取移动对象
  15. ABP框架学习
  16. requirejs源码分析
  17. MVC源码分析 - Action/Result 过滤器(续)
  18. HDU 4821 String(2013长春现场赛I题)
  19. Linux之安装本地Python和pip
  20. Oracle 创建函数

热门文章

  1. 提高mysql性能(like搜索替换 )
  2. php正则 与 js正则
  3. hive_异常_01_(未解决)FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.apache.hadoop.hbase.HTableDescriptor.addFamily(Lorg/apache/hadoop/hbase/HColumnDescriptor;)V
  4. ELK之Elasticsearch
  5. 17-比赛2 C - Maze (dfs)
  6. 16 Django-admin管理工具
  7. win7重装后恢复grub和ubuntu14
  8. how to export chrome speed dial extension?
  9. 解决NSTimer循环引用
  10. 这是我见过最厉害的--智能代码生成器、html+js+底层+sql全都有、瓦特平台