#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll rubahjadisatudigit(ll x) {
if(x >= 0 && x <= 9) return x;
ll res = x%10 + rubahjadisatudigit(x/10);
while(res > 9) res = res%10 + rubahjadisatudigit(res/10);
return res;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n; cin >> n;
for(ll i = 0;i < n; i++) {
ll l, r; cin >> l >> r;
ll ans = 0;
for(ll j = l; j <= r; j++) {
ans += rubahjadisatudigit(j);
}
cout << ans << endl;
// cout << ans;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
456 KB |
Output is correct |
4 |
Execution timed out |
1084 ms |
348 KB |
Time limit exceeded |
5 |
Execution timed out |
1067 ms |
348 KB |
Time limit exceeded |