# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199472 | SamAnd | Trol (COCI19_trol) | C++17 | 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>
using namespace std;
const int N = 102;
int dp[N];
int sum(int x)
{
int ans = 0;
while (x)
{
ans += (x % 10);
x /= 10;
}
return ans;
}
long long p(long long x)
{
if (x == 0)
return 0;
long long ans = 0;
ans += (x / 9) * (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9);
for (int i = 1; i <= (x % 9); ++i)
ans += i;
return ans;
}
int main()
{
/*for (int i = 1; i < N; ++i)
{
if (i <= 9)
dp[i] = i;
else
dp[i] = dp[sum(i)];
printf("%d %d\n", i, dp[i]);
}*/
int tt;
scanf("%d", &tt);
while (tt--)
{
long long l, r;
scanf("%lld%lld", &l, &r);
printf("%lld\n", p(r) - p(l - 1));
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |