Submission #321447

# Submission time Handle Problem Language Result Execution time Memory
321447 2020-11-12T11:03:15 Z ronnith Trol (COCI19_trol) C++14
50 / 50
1 ms 364 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#warning Check Integer OverFlow
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>=b;i--)
#define trav(a,b) for(auto a:b)
#define sz(a) a.size()
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#ifdef LOCAL 
	#define dbg(x) cerr<<"["<<#x<<":"<<x<<"] "
	#define dbg2(a,b) dbg(a);dbg(b)
	#define dbg3(a,b,c) dbg2(a,b);dbg(c)
	#define dln cerr << ln
#else
	#define dbg(x) 0
	#define dbg2(a,b) 0
	#define dbg3(a,b,c) 0
	#define dln 0
#endif
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (((a)/(__gcd(a,b))) * b)
#define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln;
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define v vector
#define p pair
#define pii p<int,int>
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;
ll modF=1e9+7;

template<class T> using iset = tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;

/*INPUT
1
1 5

2
9 13
44 45

1
1998 2018

*/

// ll val(ll a)
// {
// 	if(a < 10) return a;
// 	ll sm = 0;
// 	while(a > 0)
// 	{
// 		sm += (a % 10);
// 		a /= 10;
// 	}
// 	return val(sm);
// }

ll val(ll a)
{
	if(a % 9 == 0)return 9;
	else return a % 9;
}

void solve(){
	ll a,b;
	cin >> a >> b;
	ll ans = 0;
	for(;val(a) != 1 and a <= b;a ++)
	{
		// dbg(a % 10);
		ans += val(a);
	}
	if(a > b)
	{
		cout << ans << '\n';
		return; 
	}
	// dbg((b - a + 1));
	// dbg(((b - a + 1) / 10) * ((5 * (10 + 1))));
	ans += ((b - a + 1) / 9) * ((5 * (9)));
	a = ((b - a + 1) / 9) * 9 + a;
	for(;a <= b;a ++)
	{
		ans += val(a);
	}
	cout << ans << '\n';
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int t = 1;
	cin >> t;
	while(t --){
		solve();
	}
}

Compilation message

trol.cpp:4:2: warning: #warning Check Integer OverFlow [-Wcpp]
    4 | #warning Check Integer OverFlow
      |  ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct