Submission #977156

# Submission time Handle Problem Language Result Execution time Memory
977156 2024-05-07T12:37:05 Z vjudge1 Trol (COCI19_trol) C++17
50 / 50
1 ms 348 KB
#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 time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct