#include <bits/stdc++.h>
using namespace std;
int sumDigits(int num) {
int sum = 0;
while (num > 0) {
sum += num % 10;
num /= 10;
}
if(sum>9){
return sumDigits(sum);
}else{
return sum;
}
}
int main(){
int q;
cin>>q;
while (q--)
{
long long l,r;
cin>>l>>r;
int awal=sumDigits(l);
int ans=awal;
int tambahan=2;
int z=awal;
for (int i = 0; i < r-l; i++)
{
if(z==9){
z=1;
tambahan=1;
}
ans+=tambahan;
tambahan++;
z++;
}
cout<<ans<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Execution timed out |
1031 ms |
600 KB |
Time limit exceeded |
5 |
Execution timed out |
1047 ms |
348 KB |
Time limit exceeded |