#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fi first
#define se second
#define pb push_back
#define int long long
using namespace std;
typedef long long ll;
typedef tuple<int, int, int> iii;
int t=1+2+3+4+5+6+7+8+9;
int mod(int x){
int r= x%9;
if(!r)r=9;
return r;
}
int32_t main(){
int q;
cin>>q;
while(q--){
int l, r;
cin>>l>>r;
int ans=0;
bool c=false;
for(int i=mod(l);i<=9;i++){
ans+=i;
if(l+(i-l%9)==r){
c=true;
break;
}
}
if(c){
cout<<ans<<endl;
continue;
}
l+=9-mod(l)+1;
for(int i=1;i<=r%9;i++){
ans+=i;
}
r-=r%9;
ans+=(r-l+1)/9*t;
cout<<ans<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |