Submission #217383

#TimeUsernameProblemLanguageResultExecution timeMemory
217383bayemirovTrol (COCI19_trol)C++17
50 / 50
5 ms384 KiB
//bayemirov #include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; #define pb push_back ll g(ll x) { return x * (x + 1) / 2; } ll sumofDigits(ll x, ll res = 0) { while (x) { res += x % 10; x /= 10; } return res; } ll get(ll x) { while (x >= 10) x = sumofDigits(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 ans = 0; ll pref = get(l); ll suff = get(r); ll k = r/9 - (l-1)/9; if (pref > 1) k--; if (k == 0) { while (l <= r) { ans += get(l); l++; } cout << ans << "\n"; continue; } ans = k * 45; while (pref > 1ll && pref < 10ll) ans += pref++; if (suff < 9) ans += g(suff); cout << ans << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...