Submission #1149591

#TimeUsernameProblemLanguageResultExecution timeMemory
1149591rahidilbayramliTrol (COCI19_trol)C++20
50 / 50
2 ms328 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define vl vector<ll> #define vi vector<int> #define pb push_back #define sz(v) (ll)(v.size()) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.end() #define f first #define s second #define pll pair<ll, ll> #define pii pair<int, int> using namespace std; using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>ordered_set; ll f(ll x) { ll y = x, sum = 0; while(y >= 10){ sum = 0; while(y) { sum += (y % 10); y /= 10; } y = sum; } return y; } void solve() { ll l, r, i, j; cin >> l >> r; if(r - l <= 999) { ll sum = 0; for(i = l; i <= r; i++) sum += f(i); cout << sum << "\n"; } else { ll res = 0; while(f(l) != 1) { res += f(l); l++; } while(f(r) != 9) { res += f(r); r--; } cout << res + (r - l + 1) * 5 << "\n"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll tests = 1; cin >> tests; while(tests--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...