#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int num(long long x)
{
if((x%10)==x)return x;
long long y=0;
while(x)
{
y+=(x%10);
x/=10;
}
return num(y);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int t;
cin>>t;
while(t--)
{
long long l,r,sum=0,f=0,ni=(1+2+3+4+5+6+7+8+9);
cin>>l>>r;
while(true)
{
int x=num(l);
sum+=x;
if(x==9)break;
if(l==r)
{
f=1;
break;
}
l++;
}
while(true)
{
int x=num(r);
if(f||x==9)break;
sum+=x;
r--;
}
cout<<sum+(((r-l)/9)*ni)<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |