Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define task "TESTCODE"
- using namespace std;
- long long f[19][10][2][2];
- long long a, b;
- string s;
- long long Count(int i, int bef, bool zeros, bool low)
- {
- if (i == s.length())
- {
- return 1;
- }
- long long &res = f[i][bef][zeros][low];
- if (res != -1)
- {
- return res;
- }
- res = 0;
- int lim = s[i] - '0';
- if (low)
- {
- lim = 9;
- }
- for (int j = 0; j <= lim; ++ j)
- {
- if (j != bef || zeros == 0)
- {
- res += Count(i + 1, j, zeros | j, low | (j < s[i] - '0'));
- }
- }
- return res;
- }
- long long Get(long long x)
- {
- s = to_string(x);
- memset(f, -1, sizeof(f));
- return Count(0,0,0,0);
- }
- void read()
- {
- cin >> a >> b;
- }
- void solve()
- {
- cout << Get(b) - Get(a - 1);
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- //freopen(task".INP", "r", stdin);
- //freopen(task".OUT", "w", stdout);
- int t = 1;
- bool typetest =false;
- if (typetest)
- {
- cin >> t;
- }
- for (int _ = 1; _ <= t; ++ _ )
- {
- read();
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement