#include <bits/stdc++.h>
using namespace std;
long long f(long long l,long long r){
long long ret=0;
long long awal=l;
for (long long i = l; i<=r; i++)
{
ret+=i%9;
awal=i;
if(i%9==0){
ret+=9;
break;
}
}
long long akhir=awal;
for (long long i = r; i%9!=0 && i>awal; i--)
{
ret+=i%9;
akhir=i;
}
if(r%9==0 ){
ret+=((r-awal)/9)*45;
}else{
ret+=((akhir-awal)/9)*45;
}
return ret;
}
int main(){
int q;
cin>>q;
while ( q--)
{
long long l,r;
cin>>l>>r;
cout<<f(l,r)<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |