码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 359 C - Robbers' watch

时间:2016-07-15 23:52:16      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

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[10];
bool judge(int x ,int len)
{
    int sum=0;
    while(x)
    {
        if(vis[x%7])
        {
            return 0;
        }
        vis[x%7]=1;
        x/=7;
        sum++;
    }
    for(int i=sum; i<len; i++)
    {
        if(vis[0]==1) return 0;
        vis[0]=1;
    }
    return 1;
}
int n,m;
int main()
{
    scanf("%d%d",&n,&m);
    int ans=0;
    int len1=1;
    int len2=1;
    for(int i=7; i<n; i*=7) len1++;
    for(int i=7; i<m; i*=7) len2++;
    if(len1+len2<=7)
    {
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<m; j++)
            {
                memset(vis,0,sizeof(vis));
                if(i==j||(!judge(i,len1))||(!judge(j,len2))) continue; //判断是否重复
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
View Code

 

codeforces 359 C - Robbers' watch

标签:

原文地址:http://www.cnblogs.com/hfc-xx/p/5674654.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!