题意: 求高位往低位递减且 高位%低位==0(相邻) 数字数量
唯一要注意的就是前导零!!!!!!(正因为这个前导零 一开始的pre设置为0 )
比如 11 10 09 08 07 06 05 .。。。。说明要判断前导零
#include<bits/stdc++.h> using namespace std; //input by bxd #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i>=(b);--i) #define RI(n) scanf("%d",&(n)) #define RII(n,m) scanf("%d%d",&n,&m) #define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k) #define RS(s) scanf("%s",s); #define ll long long #define REP(i,N) for(int i=0;i<(N);i++) #define CLR(A,v) memset(A,v,sizeof A) ////////////////////////////////// #define inf 0x3f3f3f3f #define N 10+5 ll dp[N][15]; ll a[N]; ll dfs(int pos,int pre, bool lead,bool limit ) { if(!pos)return 1; if(!limit&&!lead&&dp[pos][pre]!=-1)return dp[pos][pre]; ll ans=0; int up=limit?a[pos]:9; rep(i,0,up) { if(lead||pre>=i&&i&&pre%i==0) ans+=dfs(pos-1,i, lead&&i==0,limit&&i==a[pos]); } if(!limit&&!lead)dp[pos][pre]=ans; return ans; } ll solve(ll x) { int pos=0; while(x) { a[++pos]=x%10; x/=10; } return dfs(pos,0,true,true); } int main() { int cas; RI(cas); CLR(dp,-1); while(cas--) { ll a,b; cin>>a>>b; printf("%lld ",solve(b)-solve(a-1)); } return 0; }