제출 #217251

#제출 시각아이디문제언어결과실행 시간메모리
217251bayemirovTrol (COCI19_trol)C++17
30 / 50
1094 ms384 KiB
//bayemirov                                       
#include <bits/stdc++.h>               

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;

#define pb push_back

ll sumofDigits(ll x, ll res = 0) {
	while (x) {
		res += x % 10;
		x /= 10;
	}
	return res;
}

bool ok(ll x) {
	return x < 10;
}

ll get(ll x) {
	while (!ok(x))
		 x = sumofDigits(x);
	return x;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int q;
	cin >> q;
	while (q--) {
	   ll l, r;
	   cin >> l >> r;
	   ll ans = 0;
	   while (l <= r) {
	     	ans += get(l);
	     	l++;
	   }
	   cout << ans << "\n";
	}
	return 0;
}                    
#Verdict Execution timeMemoryGrader output
Fetching results...