This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define loop(a, b) for(int a = 0; a < b; ++a)
#define loop1(a, b) for(int a = 1; a <= b; ++a)
#define loopc(a, c, b) for(int a = c; a < b; ++a)
#define loopr(a, b) for(int a = b-1; a >= 0; --a)
#define mp make_pair
using namespace std;
typedef unsigned long long ull;
vector<int> aa, bb;
ull ai, bi, p, av=0, bv=0, v;
set<int> pos;
int prev=-1, prev2=-1, as, bs;
int main() {
cin >> ai >> bi;
++bi;
loopr(a, ceil(log10(ai))) {
p = 1;
loop(w, a) p *= 10;
aa.push_back((ai / p) % (ull)10);
//cout << aa.back() << endl;
}
loopr(b, ceil(log10(bi))) {
p = 1;
loop(w, b) p *= 10;
bb.push_back((bi / p) % (ull)10);
//cout << bb.back() << endl;
}
loop(a, 10) pos.insert(a);
as = aa.size();
loop(a, as) {
if (a == 0) {
v = aa[0];
if (as > 1) v *= 9;
loopc(w, 2, as) v *= 8;
av = v;
}
else {
v = aa[a] - (int)(aa[a] > aa[a-1]);
if (a > 1) v -= (int)(aa[a] > aa[a-2]);
loopc(w, a+1, as) v *= 8;
av += v;
}
//cout << av << endl;
}
bs = bb.size();
loop(b, bs) {
if (b == 0) {
v = bb[0];
if (bs > 1) v *= 9;
loopc(w, 2, bs) v *= 8;
bv = v;
}
else {
v = bb[b] - (int)(bb[b] > bb[b-1]);
if (b > 1) v -= (int)(bb[b] > bb[b-2]);
loopc(w, b+1, bs) v *= 8;
bv += v;
}
//cout << bv << endl;
}
cout << bv - av << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |