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

A. Robbers' watch

题目连接:

http://www.codeforces.com/contest/685/problem/A

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

2 3

Sample Output

4

Hint

题意

有n个小时,m分钟,7进制时间,问你这一天一共有多少个时间,他的数字都不相同。

题解:

差点就写数位dp了……

首先,如果这个时钟的数字超过了7位,那么肯定有相同的,根据鸽巢原理很容易判断出来

然后小于七位的,实际上数字就很少了,我们直接暴力就好了……

然后这道题就完了。

代码

#include<bits/stdc++.h>
using namespace std;

int num[10],ans;
void check(int x,int y,int n,int m)
{
    for(int i=0;i<10;i++)num[i]=0;
    if(!n)num[0]++;
    if(!m)num[0]++;
    while(n){
        num[x%7]++;
        x/=7;
        n/=7;
    }
    while(m){
        num[y%7]++;
        y/=7;
        m/=7;
    }
    for(int i=0;i<10;i++)
        if(num[i]>1)return;
    ans++;
}
int n,m;    
int main()
{
    scanf("%d%d",&n,&m);
    if(1ll*n*m>1e7){
        puts("0");
        return 0;
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            check(i,j,n-1,m-1);
    cout<<ans<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值