#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define pii pair<ll, ll>
using namespace std;
ll f(ll a){
ll ans = 0;
while(a){
ans += a % 10;
a /= 10;
}
return ans;
}
int main(){
int q; cin >> q;
while(q--){
ll l, r; cin >> l >> r;
ll l1 = l;
while(l1 != f(l1)){
l1 = f(l1);
}
ll r1 = r;
while(r1 != f(r1)){
r1 = f(r1);
}
ll ans = 0;
while(l1 != 1 && l <= r){
ans += l1;
l1++;
if(l1 == 10) l1 = 1;
l++;
}
while(r1 != 9 && l <= r){
ans += r1;
r1--;
if(r1 == 0) r1 = 9;
r--;
}
ans += (r - l + 3) / 10 * 10 * 9 / 2;
cout << ans << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |