//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define speedup ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
typedef pair<int, int> PII;
ll mod = 1e9+7;
ll inf = 1e18;
int dig(ll n){
ll ret = 0;
while(n){
ret += n % 10;
n /= 10;
}
return ret;
}
int main()
{
speedup;
int t;
cin >> t;
while(t--){
ll l, r, dif, i = 0, ans = 0;
cin >> l >> r;
dif = r - l;
ll st = l;
while(st > 9){
st = dig(st);
}
while(i < 9 && dif >= 0){
if(st > 9) st = 1;
ans += st + ((dif / 9) * st);
st++;
dif--;
i++;
}
cout << ans << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
384 KB |
Output is correct |