Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Make CSP great again
- #include <bits/stdc++.h>
- #define TASK "TESTCODE"
- using namespace std;
- string s;
- long long f[10][100][2][2], a, b;
- long long dp(int i, int numzeros, bool low, bool zeros)
- {
- if (i == s.length())
- {
- return numzeros;
- }
- long long &res = f[i][numzeros][low][zeros];
- if (res != - 1)
- {
- return res;
- }
- res = 0;
- int k = s[i] - '0';
- if (low)
- {
- k = 9;
- }
- for (int j = 0; j <= k; ++ j)
- {
- if (zeros == 0 && j == 0)
- {
- res += dp(i + 1, numzeros, low | j < (s[i] - '0'), zeros | (j != 0));
- }
- else
- {
- res += dp(i + 1, numzeros + (j == 0), low | j < (s[i] - '0'), zeros | (j != 0));
- }
- }
- return res;
- }
- long long Get(long long x)
- {
- s = to_string(x);
- memset(f, -1, sizeof(f));
- return dp(0, 0, 0, 0);
- }
- void read()
- {
- cin >> a >> b;
- }
- void solve()
- {
- if (a == 0)
- {
- cout << Get(b) - Get(a) + 1 << '\n';
- }
- else
- {
- cout << Get(b) - Get(a - 1) << '\n';
- }
- }
- 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 = true;
- if (typetest)
- {
- cin >> t;
- }
- for (int __ = 1; __ <= t; ++ __)
- {
- cout << "Case " << __ << ": ";
- read();
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement