Submission #725408

#TimeUsernameProblemLanguageResultExecution timeMemory
725408TheSahibTrol (COCI19_trol)C++17
10 / 50
1 ms304 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define ll long long #define pii pair<ll, ll> using namespace std; ll f(ll a){ ll ans = 0; while(a){ ans += a % 10; a /= 10; } return ans; } int main(){ int q; cin >> q; while(q--){ ll l, r; cin >> l >> r; ll l1 = l; while(l1 != f(l1)){ l1 = f(l1); } ll r1 = r; while(r1 != f(r1)){ r1 = f(r1); } ll ans = 0; while(l1 != 1 && l <= r){ ans += l1; l1++; if(l1 == 10) l1 = 1; l++; } while(r1 != 9 && l <= r){ ans += r1; r1--; if(r1 == 0) r1 = 9; r--; } ans += (r - l + 3) / 10 * 10 * 9 / 2; cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...