#include <bits/stdc++.h>
int main(){
int q;
std::cin >> q;
int l[q], r[q];
for(int i = 0;i < q;i++){
std::cin >> l[i] >> r[i];
}
for(int i = 0;i < q;i++){
int res = 0;
for(int j = l[i];j <= r[i];j++){
int num = j;
if(num > 9){
std::string stringified = std::to_string(num);
while(stringified.size() > 1){
int pt = 0;
for(int k = 0;k < stringified.size();k++){
pt += stringified[k] - '0';
}
if(pt > 9){
stringified = std::to_string(pt);
}else{
num = pt;
break;
}
}
}
res += num;
}
std::cout << res << std::endl;
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |