Submission #199190

#TimeUsernameProblemLanguageResultExecution timeMemory
199190silxikysTrol (COCI19_trol)C++14
50 / 50
54 ms376 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; ll f(ll x) { ll d = 0; while (x > 0) { d += x % 10; x /= 10; } return d < 10 ? d : f(d); } int main() { int t; cin >> t; while (t--) { ll l, r; cin >> l >> r; if (r-l <= 1000) { ll ans = 0; for (ll i = l; i <= r; i++) { ans += f(i); } cout << ans << '\n'; continue; } ll ans = 0; while (l <= r && l % 9 != 1) { ans += f(l); l++; } while (r >= l && r % 9 != 0) { ans += f(r); r--; } ll num = (r-l+1)/9; ans += 45LL*num; cout << ans << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...