#include <iostream>
#define ll long long
using namespace std;
// Fungsi untuk mengurangi angka menjadi satu digit dengan menjumlahkan digit-digitnya
int reduceToOneDigit(int num) {
while (num >= 10) {
int sum = 0;
while (num > 0) {
sum += num % 10;
num /= 10;
}
num = sum;
}
return num;
}
int main() {
int q;
cin >> q; // Membaca jumlah pertanyaan
while (q--) {
ll l, r;
cin >> l >> r; // Membaca rentang L dan R
ll ans = 0;
for (ll i = l; i <= r; ++i) {
ans += reduceToOneDigit(i);
}
cout << ans << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
432 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
4 |
Execution timed out |
1097 ms |
416 KB |
Time limit exceeded |
5 |
Execution timed out |
1062 ms |
348 KB |
Time limit exceeded |