# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1257402 | tatas07 | Trol (COCI19_trol) | C++17 | 0 ms | 328 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int batas_bawah(int n)
{
if (n % 9 == 1)
{
return n;
}
for (int i = 1; i <= 8; i++)
{
if ((n - i) % 9 == 1)
{
return n - i;
}
}
}
int batas_atas(int n)
{
if (n % 9 == 0)
{
return n;
}
for (int i = 1; i <= 8; i++)
{
if ((n + i) % 9 == 0)
{
return n + i;
}
}
}
int hasil(int x)
{
if (x % 9 == 0)
{
return 9;
}
return x % 9;
}
int hitung(int l, int r)
{
int atas = batas_atas(r);
int bawah = batas_bawah(l);
int ans = ((atas - bawah + 1) * 5);
for (int i = r + 1; i <= atas; i++)
{
ans -= hasil(i);
}
for (int i = l - 1; i >= bawah; i--)
{
ans -= hasil(i);
}
return ans;
}
signed main()
{
int q;
cin >> q;
while (q--)
{
int l, r;
cin >> l >> r;
cout << hitung(l, r) << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |