#include <iostream>
#include <vector>
using namespace std;
int digitSum(int x) {
int sum = 0;
while (x > 0) {
sum += x % 10;
x /= 10;
}
if (sum >= 10) {
return digitSum(sum);
}
return sum;
}
int main() {
int q;
cin >> q;
vector<int> answers;
for (int i = 0; i < q; ++i) {
int l, r;
cin >> l >> r;
int sum = 0;
for (int j = l; j <= r; ++j) {
sum += digitSum(j);
}
answers.push_back(sum);
}
for (int ans : answers) {
cout << ans << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Execution timed out |
1087 ms |
348 KB |
Time limit exceeded |
5 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |