# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
205407 | luciocf | Trol (COCI19_trol) | C++14 | 5 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>
typedef long long ll;
using namespace std;
int main(void)
{
int q;
scanf("%d", &q);
while(q--)
{
long long l, r;
scanf("%lld %lld", &l, &r);
if (r-l+1 <= 9)
{
int ans = 0;
for (ll i = l; i <= r; i++)
{
ll x = i%9;
if (x == 0) x = 9;
ans += x;
}
printf("%d\n", ans);
}
else
{
ll ans = 0;
ll a;
for (ll i = l; i <= r; i++)
{
ll x = i%9;
if (x == 0) x = 9;
ans += 1ll*x;
if (x == 9)
{
a = i+1;
break;
}
}
ll b;
for (ll i = r; i >= l; i--)
{
ll x = i%9;
if (x == 0) x = 9;
ans += x;
if (x == 1)
{
b = i-1;
break;
}
}
ans += 45ll*((b-a+1)/9);
printf("%lld\n", ans);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |