对于数位dp高精度的处理方式,同此题。
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e3+5,MOD=1e9+7;
int m,d,len,ans;
int a[N],dp[N][N];
char l[N],r[N];
int dfs(int x,int sum,int lead,int limit)
{
if (x==len+1)
{
if (!sum && !lead) return 1;
return 0;
}
if (!lead && !limit && ~dp[x][sum])
{
return dp[x][sum];
}
int res=0;
int h;
if (limit) h=a[x]; else h=9;
for (register int i=0; i<=h; ++i)
{
if (x%2==0 && i!=d) continue;
if (x%2==1 && i==d) continue;
res=(res+dfs(x+1,(sum*10+i)%m,(i==0)&&lead,(i==h)&&limit))%MOD;
}
if (!limit && !lead)
{
dp[x][sum]=res;
}
return res;
}
inline int solve(char s[])
{
len=strlen(s);
for (register int i=1; i<=len; ++i) a[i]=s[i-1]-'0';
return dfs(1,0,1,1);
}
signed main(){
memset(dp,-1,sizeof(dp));
scanf("%lld%lld",&m,&d);
scanf("%s",l+1);
scanf("%s",r+1);
ans=((solve(r+1)-solve(l+1))%MOD+MOD)%MOD;
bool jay=true;
int now=0;
for (register int i=1; i<=len; ++i)
{
a[i]=l[i]-'0';
if (i%2==0 && a[i]!=d) {jay=false; break;}
if (i%2==1 && a[i]==d) {jay=false; break;}
now=(now*10+a[i])%m;
}
if (now) jay=false;
if (jay) ans=(ans+1)%MOD;
printf("%lld\n",ans);
return 0;
}