Topic Link
Meaning of the questions is really annoying, to finally know that this is in fact the number of bits n m-two time zones defined table, so that when the number is not enough to fill the time zone when the front of the automatic zero-padded
Ideas: First, it can not have duplicate numbers, then the total number of bits in hours and minutes is more than 7 certainly not.
7 of 7 th has only 823,543
So we enumerated from the i from 0 to n, j from 0 to m can be enumerated. Why complexity is correct?
In fact, considering LenN + LenM <= 7 and n * m is the maximum number (the number of bits representing Len)
Consider two extreme N1 bits, M6 bits, maximum 7 * 7 ^ 6 just good 7 th 7
N4 position, M3 maximum bit 3 * 7 ^ 7 ^ 7 ^ 4 or 7, is less than the complexity 1e6
//#pragma comment (linker, "/STACK:102400000,102400000")
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<list>
#include<time.h>
#define myself i,l,r
#define lson i<<1
#define rson i<<1|1
#define Lson i<<1,l,mid
#define Rson i<<1|1,mid+1,r
#define half (l+r)/2
#define lowbit(x) x&(-x)
#define min4(a, b, c, d) min(min(a,b),min(c,d))
#define min3(x, y, z) min(min(x,y),z)
#define max3(x, y, z) max(max(x,y),z)
#define max4(a, b, c, d) max(max(a,b),max(c,d))
//freopen("E://1.in","r",stdin);
//freopen("E://1.out","w",stdout);
typedef unsigned long long ull;
typedef long long ll;
#define pii make_pair
#define pr pair<int,int>
const int inff = 0x3f3f3f3f;
const int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
const int mdir[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 1, -1, -1, -1};
const double eps = 1e-10;
const double PI = acos(-1.0);
const double E = 2.718281828459;
using namespace std;
const long long inFF = 9223372036854775807;
const int mod=1e9+7;
const int maxn=1e5+5;
int a[7];
int len1,len2;
int cal(ll x)
{
x--;
if(x==0) return 1;
int ans=0;
while(x){x/=7;ans++;}
return ans;
}
bool check(int x,int y)
{
int cnt=0;
memset(a,0,sizeof(a));
while(x){a[x%7]++;x/=7;cnt++;}
a[0]+=len1-cnt;
cnt=0;
while(y){a[y%7]++;y/=7;cnt++;}
a[0]+=len2-cnt;
for(int i=0;i<=6;i++)
if(a[i]>=2)
return 0;
return 1;
}
int main()
{
ll n,m;
cin>>n>>m;
len1=cal(n),len2=cal(m);
if(len1+len2>7)
{
cout<<0<<endl;
return 0;
}
ll ans=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(check(i,j)) ans++;
cout<<ans<<endl;
}