Submission #199189

# Submission time Handle Problem Language Result Execution time Memory
199189 2020-01-29T23:41:58 Z silxikys Trol (COCI19_trol) C++14
30 / 50
5 ms 376 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int f(int x) {
    int 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 <= 100) {
            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 += 45*num;
        cout << ans << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Incorrect 5 ms 376 KB Output isn't correct
4 Correct 5 ms 256 KB Output is correct
5 Incorrect 5 ms 376 KB Output isn't correct