제출 #1258104

#제출 시각아이디문제언어결과실행 시간메모리
1258104ykc0606Trol (COCI19_trol)C++20
50 / 50
0 ms328 KiB
#include <bits/stdc++.h>
#define int long long 
#define N 200005
using namespace std;

int f(int x){
	int s=0;
	while(x){
		s+=x%10;
		x/=10;
	}
	if(s>=10)return f(s);
	else return s;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL); 
	
	int q;
	cin >> q;
	while(q--){
		int l,r;
		cin >> l >> r;
		int arr[]={0,1,2,3,4,5,6,7,8,9};
		for(int i=1;i<=9;i++)arr[i]+=arr[i-1];
		int x=f(l);
		int y=f(r);
		int k=(r-l+1)-(9-x+1)-y;
		int ans=45*(k/9)+arr[9]-arr[x-1]+arr[y]-arr[0];
		cout << ans << "\n";
	}
	
	return 0;
}

/*
*/
#Verdict Execution timeMemoryGrader output
Fetching results...