Submission #1107422

# Submission time Handle Problem Language Result Execution time Memory
1107422 2024-11-01T08:11:29 Z toast12 Trol (COCI19_trol) C++14
50 / 50
1 ms 504 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int sum_of_digits(ll x) {
    if (x/10 == 0) return x;
    ll temp = 0;
    while (x > 0) {
        temp += x%10;
        x /= 10;
    }
    return sum_of_digits(temp);
}

int main() {
    int q;
    cin >> q;
    while (q--) {
        ll l, r;
        cin >> l >> r;
        ll ans = 0;
        ll tot = r-l+1;
        ll cnt = tot/9;
        ans += 1ll*45*cnt;
        for (int i = 0; i < (tot % 9); i++) {
            int x = (l+i) % 9;
            if (x == 0) x = 9;
            ans += x;
        }
        cout << ans << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct