#include<bits/stdc++.h>
using namespace std;
long long sum(long long a,long long b)
{
long long ans=0;
for(long long i=a;i<=b;i++)
{
if(i%9==0)ans+=9;
ans+=i%9;
}
return ans;
}
long long solve(long long a,long long b)
{
if(b-a<=20)return sum(a,b);
long long a2=a,b2=b,ans=0;
if(a%9!=1)a2+=(10-a%9);
if(b%9!=0)b2-=b%9;
//cout<<a2<<" "<<b2<<endl;
ans+=sum(a,a2-1);
ans+=sum(b2+1,b);//cout<<ans<<endl;
ans+=(b2-a2+1)/9*45;
return ans;
}
int main()
{
int t;
cin>>t;
while(t--)
{
long long a,b;
cin>>a>>b;
cout<<solve(a,b)<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |