rt,这份代码本地正常运行,在 双倍经验 中也 能过,但这题 RE 了,求调。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll M=2520;
ll T,l,r,ct,dp[26][M+10][55],b[2550];
vector<ll> a;
void init(){
memset(dp,-1,sizeof dp);
for(int i=1;i<=M;i++)
if(!(M%i)) b[i]=++ct;
}
ll lcm(ll x,ll y){
return x*y/__gcd(x,y);
}
ll dfs(ll x,ll last,ll l,bool up){
if(x<=-1) return !(last%l);
if(!up&&dp[x][last][b[l]]!=-1) return dp[x][last][b[l]];
ll res=0;
for(int i=0;i<=(up?a[x]:9);i++)
res+=dfs(x-1,(last*10+i)%M,(i?lcm(l,i):l),up&&(i==a[x]));
if(!up) dp[x][last][b[l]]=res;
return res;
}
ll work(ll x){
a.clear();
while(x) a.push_back(x%10),x/=10;
return a.size()-1;
}
ll calc(ll x){return dfs(work(x),0,1,1);}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>T;init();
while(T--){
cin>>l>>r;
cout<<calc(r)-calc(l-1)<<"\n";
}
return 0;
}