Submission #1111957

# Submission time Handle Problem Language Result Execution time Memory
1111957 2024-11-13T12:48:44 Z huantran Trol (COCI19_trol) C++17
50 / 50
1 ms 460 KB
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
const int maxn = 5e5 + 5;
const int oo = 1e9 + 7;
const ll inf = 1e18;
 
int sum_digit(ll x) {
    ll sum = 0;
    while (x) {
        sum += x%10;
        x /= 10;
    }
    return sum;
}

int num_trans(ll x) {
    while (x >= 10) {
        x = sum_digit(x);
    }
    return x;
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
 
    int q;
    cin >> q;
    while (q--) {
        ll l, r;
        cin >> l >> r;
        ll distance = (r - l + 1);
        ll sum = distance/9*45;
        ll rem = distance%9;
        ll start = num_trans(l);
        while (rem --> 0) {
            sum += ((start%9 == 0) ? 9 : (start%9));
            start++;
        }
        cout << sum << '\n';
    }
}
# 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 460 KB Output is correct
5 Correct 1 ms 336 KB Output is correct