#pragma GCC optimize("O3", "inline")
#define skillissue <bits/stdc++.h>
#define ultra_mal std
#include skillissue
using namespace ultra_mal;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ins insert
#define pb push_back
#define int long long int
#define pii pair<int, int>
#define endl '\n'
#define drop(x) cout<<(x)<<endl; return;
#define all(x) x.begin(),x.end()
#define hash FhashF
const int mod = 1e9 +7, sze = 1E3 +100, inf = LLONG_MAX, P = 1453;
// const int L = 30;
void cave(){
int l,r;
cin>>l>>r;
int sum=0;
int lx = l;
int rx =r;
while(lx>9){
int s =0;
while(lx){
s+=lx%10;
lx/=10;
}
lx=s;
}
while(rx>9){
int s =0;
while(rx){
s+=rx%10;
rx/=10;
}
rx=s;
}
// cout<<lx<<" "<<rx<<endl;
while(lx<=9 && l<=r){
sum+=lx;
l++;
lx++;
}
while(rx>=1 && r>=l){
sum+=rx;
r--;
rx--;
}
// cout<<l<<" "<<r<<endl;
int v = ((r-l +1)/9) * 45;
sum+=v;
drop(sum);
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int tt = 1;
cin>>tt;
while(tt--){
cave();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |