Submission #974971

# Submission time Handle Problem Language Result Execution time Memory
974971 2024-05-04T08:19:09 Z vjudge1 Trol (COCI19_trol) C++17
50 / 50
1 ms 348 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i = 1; i<=n; i++)
using namespace std;

ll pref(ll x){
	return (x*(x+1))/2;
}

ll func(ll x){
	if(x <= 9)return x;
	ll temp = x;
	ll t = 0;
	while(x > 0){
		t += x%10;
		x /= 10;
	}
	return func(t);
	
}



int main(){
//	for(int i = 1; i<=100; i++){
//		cout<<i<<" : "<<func(i)<<endl;
//	}
	
	ll n;
	cin>> n;
	forn(i,n){
		ll l,r;
		cin >> l >> r;
		unsigned long long banyak = r-l+1;
		unsigned long long sum = 0;
		for(ll i = func(l); i<=9; i++){
			if(banyak == 0)break;
			sum += i;
			banyak--;
		}

		for(ll i = func(r); i>=1; i--){
			if(banyak == 0)break;
			sum += i;
			banyak--;
		}
		sum += pref(9)*(banyak/9);
		
		cout<<sum<<endl;
		
	}
	
}

Compilation message

trol.cpp: In function 'long long int func(long long int)':
trol.cpp:14:5: warning: unused variable 'temp' [-Wunused-variable]
   14 |  ll temp = x;
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct