#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define ar array
#define ld long double
#define int long long
#define all(v) v.begin(), v.end()
const int N = 2e5 + 20;
const int K = 469;
const int LOG = 26;
const int INF = 1e12;
int MOD = 998244353;
void mm(int &x){x = (x % MOD + MOD) % MOD;}
int dp[20][11][11][2];
vector<int> v;
int f(int i,int l1, int l2, bool u){
if(i == v.size())return 1;
if(dp[i][l1][l2][u] != -1)return dp[i][l1][l2][u];
int lim;
if(u)lim = 9;
else lim = v[i];
int ans = 0;
for(int x = 0;x <= lim;x++){
if(x == l1 || x == l2)continue;
bool nu = u;
if(x < lim)nu = 1;
ans += f(i + 1, x, l1, nu);
}
return dp[i][l1][l2][u] = ans;
}
int solve(int x){
v.clear();
memset(dp, -1, sizeof dp);
while(x){
v.push_back(x % 10);
x /= 10;
}
reverse(all(v));
//for(auto u: v)cout<<u<<" ";
// cout<<'\n';
return f(0, 10, 10, 0);
}
void orz(){
int a, b;
cin>>a>>b;
// cout<<solve(a - 1)<<' '<<solve(b)<<'\n';
cout<<solve(b) - solve(a - 1)<<'\n';
}
signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
int t;
//cin>>t;
t = 1;
while(t--)orz();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |