#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
trol.cpp:37:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
37 | main()
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |