原题链接
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const ll N = 15;
const ll mod = 1000000007;
ll ans = 0;
ll K, B;
ll f[N][N];
void init() {
for (int i = 0; i <= 9; i++) {
f[1][i] = 1;
}
for (int i = 2; i < N; i ++) {
for (int j = 0; j <= 9; j ++) {
for (int k = 0; k <= 9; k ++) {
if (abs(k-j)>= 2)f[i][j] += f[i-1][k];
}
}
}
}
ll DP(ll n) {
/******************************模板*********/
if (n == 0) return 0;//这个也是看情况返回0还是个1
vector<int> nums;
ll now = n;
while (now) {
nums.push_back(now % 10);
now /= 10;
}
ll res = 0, last = -4;//这个last是看情况搞
/******************************模板*********/
for (int i = nums.size() - 1; i >= 0; i--) {
ll x = nums[i];
for (int j = (i == nums.size()-1)/*是因为非最高位的话此时可以为0,如果是最高位,因为没前导0,所以为1*/; j < x; j ++) {
if (abs(j - last) >= 2)//正常判断
res += f[i+1][j];
}
if (abs(last-x) < 2)break;//原数左面是否合法
last = x;
if (!i)res++;//套路
}
for (int i = 1; i < nums.size(); i++) {
for (int j = 1; j <= 9; j ++) {//处理没有前导0的情况,
res += f[i][j];//
}
}
return res;
}
void solve() {
init();
ll l, r;
while (cin >> l >> r)cout << DP(r) - DP(l-1)<< endl;
}
signed main() {
ios::sync_with_stdio(0);
ll t = 1;
while (t--) solve();
return 0;
}