Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

 

Description

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.

Sample Input

Input
2 3
Output
4
Input
8 2
Output
5

Hint

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进制数,判断有多少种显示的方式使得时钟上每一个数字都不重复。

思路:由于只有7个数,所以n和m转化为7进制以后,如果位数多余7则一定没有解,所以只有当两个数的位数之和小于等于7的时候才有解,我们会发现此时的数是比较小的,所以我们可以直接暴力计算结果。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
bool vis[];
bool judge(int x ,int len)
{
int sum=;
while(x)
{
if(vis[x%])
{
return ;
}
vis[x%]=;
x/=;
sum++;
}
for(int i=sum; i<len; i++)
{
if(vis[]==) return ;
vis[]=;
}
return ;
}
int n,m;
int main()
{
scanf("%d%d",&n,&m);
int ans=;
int len1=;
int len2=;
for(int i=; i<n; i*=) len1++;
for(int i=; i<m; i*=) len2++;
if(len1+len2<=)
{
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
memset(vis,,sizeof(vis));
if(i==j||(!judge(i,len1))||(!judge(j,len2))) continue; //判断是否重复
ans++;
}
}
}
cout<<ans<<endl;
return ;
}

codeforces 359 C - Robbers' watch的更多相关文章

  1. 套题 codeforces 359

    A题:Free Ice Cream 注意要使用LL,避免爆int #include <bits/stdc++.h> #define scan(x,y) scanf("%d%d&q ...

  2. codeforces 686C C. Robbers' watch(dfs)

    题目链接: C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

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

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

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

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

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

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

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

  8. Codeforces 658A. Robbers' watch 模拟

    A. Robbers' watch time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

  9. Codeforces Round #359 (Div. 1)

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

随机推荐

  1. Android解析qq聊天记录表情

    偶然在一个需求中需要解析qq聊天记录表情,表情的格式是以/开始,比如:你好啊?/微笑,在网上找了半天,也没能找到一个比较合适的,所以准备自己实现一下,首先要将表情图片和表情字符对上号,我想了几种解决方 ...

  2. 一个寻找.jar 和.zip文件中class文件的工具

    相信很多人跟我一样,苦于在各种包之间,不知道Class存在什么地方,为此,自己写了一个小工具,来寻找目录下的Class文件 支持 目录查询,支持带包路径查询 入口Entrance.java packa ...

  3. ViewPager的用法

    ViewPager 1.布局文件中的配置 ViewPager的路径 方法:在源码文件中输入ViewPager,按下alt+/,上面就会出来viewPager的包路径 viewPager的配置很简单,前 ...

  4. IOS8开发之实现App消息推送

    第一部分 Apple Push Notification Service 首先第一步当然是介绍一下苹果的推送机制(APNS)咯(ps:其实每一篇教程都有),先来看一张苹果官方对其推送做出解释的概要图. ...

  5. get方式请求会出现中文乱码。post方式不会。

    get方式请求会出现中文乱码.post方式不会.   如果是要解决get方式中文乱码问题,就需要做一个拦截器,或者在web.xml做一个get请求的配置 来自为知笔记(Wiz)

  6. 复旦大学2016--2017学年第一学期高等代数I期末考试情况分析

    一.期末考试成绩班级前十名 宁盛臻(100).朱民哲(92).徐钰伦(86).范凌虎(85).沈伊南(84).何陶然(84).丁知愚(83).焦思邈(83).董瀚泽(82).钱信(81) 二.总成绩计 ...

  7. 在后台CS文件里面,隐藏和显示Repeater里面控件

    <asp:Repeater ID="Repeater1" runat="server"><ItemTemplate><asp:Pa ...

  8. Customize the SharePoint 2013 search experience with a Content Enrichment web service

    Did you ever wish you had more control over how your content is indexed and presented as search resu ...

  9. PHP-popen()&nbsp;函数打开进程文件指针

    待更新 版权声明:本文为博主原创文章,未经博主允许不得转载.

  10. PHP负载均衡

    待更新 版权声明:本文为博主原创文章,未经博主允许不得转载.