#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll digits ( ll y ){
ll sum = 1e18;
while ( sum >= 10 ){
sum = 0;
while ( y >= 1 ){
sum += (y % 10);
y /= 10;
}
y = sum;
}
return sum;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int q; cin >> q;
while ( q-- ){
ll l, r; cin >> l >> r;
ll now = l;
ll ans = 0;
while ( now <= r && digits ( now ) != 1 ){
ans += digits ( now );
now++;
}
ll temp = ( ( r - ( now - 1)) / 9 );
ans += ( temp * 45ll);
now += ( temp * 9);
for ( ll i = now; i <= r; i++){
ans += digits(i);
}
cout << ans << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |