제출 #977156

#제출 시각아이디문제언어결과실행 시간메모리
977156vjudge1Trol (COCI19_trol)C++17
50 / 50
1 ms348 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define sec second
#define pii pair<ll,ll>
 
const ll N = 1e5 + 5;
const ll MOD = 1e9 + 7;

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	ll tc = 1;
	// cin >> tc;
	while(tc--){
		ll q; cin >> q;
		for(int i=1;i<=q;i++){
			ll l,r; cin >> l >> r;
			ll dist = r-l+1;
			while(l >= 10){
				string tmp = to_string(l);
				ll cur = 0;
				for(auto i : tmp) cur += (i - '0');
				l = cur;
			}
			ll rem = dist / 9;
			ll ans = 0;
			for(int i=1;i<=(dist%9);i++){
				ans += l;
				l++;
				if(l > 9) l = 1;
			}
			ll sum = 0;
			for(int i=1;i<=9;i++){
				if(l > 9) l = 1;
				sum += l, l++;
			}
			ans += rem * sum;
			cout << ans << endl;
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...