#include <bits/stdc++.h>
using namespace std;
int long Sum(int l, int r)
{
int ret = 0;
for(int i = l; i <= r; i++)
ret += i;
return ret;
}
int main()
{
int q;
long long a, b;
cin>>q;
int sum9 = Sum(1, 9);
while(q--)
{
cin>>a>>b;
long long x = a, y = b, res = 0;
if(y - x < 20)
{
for(long long i = x; i <= y; i++)
{
res += i % 9;
if(i % 9 == 0)
res += 9;
}
cout<<res<<endl;
continue;
}
if(a % 9)
{
x += 9 - (x % 9);
res += Sum(a % 9, 9);
}
if(b % 9)
{
y -= y % 9;
res += Sum(1, b % 9);
}
if(a == x)
res += 9;
res += (y - x) / 9 * sum9;
//cout<<x<<" "<<y<<" ";
cout<<res<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |