# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
346939 | Nursik | Trol (COCI19_trol) | C++14 | 1 ms | 364 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>
#define f first
#define s second
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define ld long double
#define fi first
#define se second
using namespace std;
void data() {
#ifdef NURS
freopen("main.in", "r", stdin);
freopen("main.out", "w", stdout);
#endif
}
void win()
{
ios_base::sync_with_stdio(0),
cin.tie(0),cout.tie(0);
}
int block = 400;
const ld eps = 1e-7;
const int N = 3e5 + 500;
const int mod = 1e9 + 7;
const int mod2 = 998244353;
const ll hh = 29;
const ll hh2 = 31;
int t, sum;
main()
{
data();
win();
cin >> t;
while (t--)
{
ll l, r;
cin >> l >> r;
ll prev = l;
ll ans = 0;
while (l <= r)
{
prev = l;
while (prev / 10 > 0)
{
sum = 0;
while (prev > 0)
sum += prev % 10, prev /= 10;
prev = sum;
}
ans += prev;
if (prev == 9)
break;
l++;
}
while (r > l)
{
prev = r;
while (prev / 10 > 0)
{
sum = 0;
while (prev > 0)
sum += prev % 10, prev /= 10;
prev = sum;
}
ans += prev;
if (prev == 1)
break;
r--;
}
// cout << l << " " << r << '\n';
cout << ans + (r - l - 1) / 9 * 9 * 10 / 2 << '\n';
}
}
/*
Если я солью, то я обязательно затащю
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |