# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
218199 | maskoff | Trol (COCI19_trol) | C++14 | 1095 ms | 384 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>
#include <ext/rope>
#define file ""
#define all(x) x.begin(), x.end()
#define sc second
#define fr first
#define pb push_back
#define mp make_pair
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const int inf = 1e9;
const int MOD = 998244353;
const int N = 5e5;
const int dx[] = {+1, -1, 0, 0};
const int dy[] = {0, 0, +1, -1};
ll sum(ll x) {
ll res = 0;
while (x) {
res += x % 10;
x /= 10 ;
}
return res;
}
ll get(ll x) {
while (x >= 10) {
x = sum(x);
}
return x;
}
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
srand(time(NULL));
int q;
cin >> q;
while (q--) {
ll l, r;
cin >> l >> r;
ll ans = (r - l + 1) / 9;
ans *= 45;
if (ans == 0) {
for (int i = l; i <= r; i++)
ans += get(i);
cout << ans << endl;
continue;
}
l = get(l);
r = get(r);
if (l != 1)
for (int i = l; i <= 9; i++)
ans += i;
if (r != 9)
for (int i = 1; i <= r; i++)
ans += i;
cout << ans << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |