A - 不要62 HDU - 2089

时间:2023-03-09 03:23:43
A - 不要62 HDU - 2089
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<time.h>
#include<iostream>
#include<ctype.h>
#include<map>
#include<set>
#include<string>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
using namespace std;
#define LL long long
LL dp[][],num[];
LL dfs(int pos,int st,int limit)//pos数位,从最高位开始枚举,st表示状态,不符合状态记为2,最初状态记为0,出现6状态为1,limit为上限,达到枚举上限为1否则为0
{ int i;
if(pos<)
return st==;
if(!limit&&dp[pos][st]!=-)
return dp[pos][st];
LL ans=;
int len=limit?num[pos]:;
for(i=;i<=len;i++)
{
if(i==||i==||(st==&&i==))
ans+=dfs(pos-,,limit&&i==len);
else if(i==)
ans+= dfs(pos-,,limit&&i==len);
else
ans+=dfs(pos-,,limit&&i==len); }
if(!limit)
dp[pos][st]=ans;
return ans;
}
LL solv(LL a)
{
int len=;
memset(dp,-,sizeof(dp));
memset(num,-,sizeof(num));
while(a)
{
num[len++]=a%;
a/=;
}
dfs(len-,,);
}
int main()
{
int t,n,m;
while(~scanf("%d%d",&n,&m))
{
if(n==&&m==)
break;
LL ee=solv(m)-solv(n-);
printf("%lld\n",m-n+-ee); } }