# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199190 | silxikys | Trol (COCI19_trol) | C++14 | 54 ms | 376 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;
ll f(ll x) {
ll d = 0;
while (x > 0) {
d += x % 10;
x /= 10;
}
return d < 10 ? d : f(d);
}
int main() {
int t; cin >> t;
while (t--) {
ll l, r; cin >> l >> r;
if (r-l <= 1000) {
ll ans = 0;
for (ll i = l; i <= r; i++) {
ans += f(i);
}
cout << ans << '\n';
continue;
}
ll ans = 0;
while (l <= r && l % 9 != 1) {
ans += f(l);
l++;
}
while (r >= l && r % 9 != 0) {
ans += f(r);
r--;
}
ll num = (r-l+1)/9;
ans += 45LL*num;
cout << ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |