| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 238743 | Halit | Trol (COCI19_trol) | C++17 | 1095 ms | 384 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const bool cannot = 0;
int main(){
	int q;
	cin >> q;
	while(q--){
		long long l,r, ans = 0, sootnp, lp = 0, rp = 0, ran_l, ran_r;
		cin >> l >> r;
		if(r - l + 1 <= 9){
			for(int i = l;i <= r;i++)
				ans += i % 9 + (i % 9 == 0) * 9;
			cout << ans << "\n";
			continue; 
		}
		for(int i = l;i <= min(r , l+9) ;i++){
			if(i % 9 == 1){
				ran_l = i;
				break;
			}
		}
		for(int i = r;i >= max(l, r - 9);i--){
			if(i % 9 == 1){
				ran_r = i;
				break;
			}
		}
		sootnp = (ran_r - ran_l + 1) / 9 * 45;
		for(int i = l;i < ran_l;i++)
			lp += i % 9 + (i % 9 == 0) * 9;
		
		for(int i = r;i >= ran_r;i--)
			rp += i % 9 + (i % 9 == 0) * 9;
		ans = sootnp + lp + rp;
		cout << ans << "\n";
		}
}
// ans = sum_of_one_to_nine_parts + left_part + right_part;
// sootnp starts with 1 and ends with 9
// reminders are same (1,9 -> 0) ^^^^
// for loop to find beginning and end
// sootnp = (range_length + 1) / 9 * 45
// find rigth&left_part with for
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
