#include <bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int dig(ll i){
while(i>9){
ll nilai=i, jdg=0;
while(nilai!=0){
jdg+=nilai%10;
nilai/=10;
}
i= jdg;
}
return i;
}
int jumlah(ll p,ll r){
ll jum=0;
for(ll i=p; i<= r; i++){
jum+=dig(i);
}
return jum;
}
int main(){
fastio;
ll q;
cin>>q;
while(q--){
ll p, r;
cin>>p>>r;
cout<<jumlah(p, r)<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Execution timed out |
1094 ms |
432 KB |
Time limit exceeded |
5 |
Execution timed out |
1058 ms |
348 KB |
Time limit exceeded |