思路:分类讨论+递推
记录
#include<bits/stdc++.h>
#define int long long
using namespace std;
int l,r;
int qpow(int a,int b){
int res=1;
while (b>0){
if (b&1) res*=a;
b/=2;
a*=a;
}
return res;
}
int digi[25];
int get(int x){
int t=0,ans=0;
while (x>0){
digi[++t]=x%10;
x/=10;
}
for (int i=2;i<t;i++){
for (int j=1;j<=9;j++){
ans+=qpow(j,i-1);
}
}
for (int j=1;j<digi[t];j++){
ans+=qpow(j,t-1);
}
int res=1;
for (int i=t-1;i>0;i--){
res=(res-1)*digi[t]+min(digi[i],digi[t]-1)+1;
}
return ans+res-1;
}
signed main(){
ios::sync_with_stdio(0);
cin>>l>>r;
cout<<get(r)-get(l-1);
return 0;
}