Submission #1111957

#TimeUsernameProblemLanguageResultExecution timeMemory
1111957huantranTrol (COCI19_trol)C++17
50 / 50
1 ms460 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int maxn = 5e5 + 5; const int oo = 1e9 + 7; const ll inf = 1e18; int sum_digit(ll x) { ll sum = 0; while (x) { sum += x%10; x /= 10; } return sum; } int num_trans(ll x) { while (x >= 10) { x = sum_digit(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 distance = (r - l + 1); ll sum = distance/9*45; ll rem = distance%9; ll start = num_trans(l); while (rem --> 0) { sum += ((start%9 == 0) ? 9 : (start%9)); start++; } cout << sum << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...