# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1111957 | huantran | Trol (COCI19_trol) | C++17 | 1 ms | 460 KiB |
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>
using namespace std;
using ll = long long int;
const int maxn = 5e5 + 5;
const int oo = 1e9 + 7;
const ll inf = 1e18;
int sum_digit(ll x) {
ll sum = 0;
while (x) {
sum += x%10;
x /= 10;
}
return sum;
}
int num_trans(ll x) {
while (x >= 10) {
x = sum_digit(x);
}
return x;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int q;
cin >> q;
while (q--) {
ll l, r;
cin >> l >> r;
ll distance = (r - l + 1);
ll sum = distance/9*45;
ll rem = distance%9;
ll start = num_trans(l);
while (rem --> 0) {
sum += ((start%9 == 0) ? 9 : (start%9));
start++;
}
cout << sum << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |