#include <bits/stdc++.h>
using namespace std;
int main(){
int q;cin>>q;
int ans[q];
for(int k=0;k<q;k++){
int l,r;cin>>l>>r;
int kanan,kiri;
int x=(r/9)*9;
int x45=(r/9)*45;
int cnt1=0;
for(int i=x+1;i<=r;i++){
if(i%9!=0){
cnt1+=i%9;
}else{
cnt1+=9;
}
}
kanan=x45+cnt1;
int cnt2=0;
x=((l-1)/9)*9;
x45=((l-1)/9)*45;
for(int i=x+1;i<=l-1;i++){
if(i%9!=0){
cnt2+=i%9;
}else{
cnt2+=9;
}
}
kiri=x45+cnt2;
ans[k]=kanan-kiri;
}
for(int i=0;i<q;i++){
cout<<ans[i]<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Correct |
1 ms |
500 KB |
Output is correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |