Submission #976665

# Submission time Handle Problem Language Result Execution time Memory
976665 2024-05-07T01:44:38 Z vjudge1 Trol (COCI19_trol) C++17
50 / 50
1 ms 348 KB
#include <iostream>
#include <cmath>
using namespace std;

const int SUM = 45;

uint64_t calc(uint64_t l, uint64_t r) {
    l--;
    return (r/9 - l/9) * SUM + (r % 9)*(r % 9 + 1)/2 - (l % 9)*(l % 9 + 1)/2;
}

int main() {
    int q;
    uint64_t l, r;
    cin >> q;
    while (q--) {
        cin >> l >> r;
        if (l == r) {
            cout << (l % 9 ? l % 9 : 9) << '\n';
            continue;
        }
        cout << calc(l, r) << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct