#include <iostream>
using namespace std;
// Fungsi untuk menghitung jumlah digit hingga menjadi satu digit
int singleDigitSum(int n) {
while (n >= 10) {
int sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
n = sum;
}
return n;
}
int main() {
int Q;
cin >> Q; // Membaca jumlah pertanyaan
for (int i = 0; i < Q; ++i) {
long long L, R;
cin >> L >> R;
long long totalSum = 0;
for (long long j = L; j <= R; ++j) {
totalSum += singleDigitSum(j);
}
cout << totalSum << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
4 |
Execution timed out |
1062 ms |
408 KB |
Time limit exceeded |
5 |
Execution timed out |
1066 ms |
348 KB |
Time limit exceeded |