Submission #1254485

#TimeUsernameProblemLanguageResultExecution timeMemory
1254485__ugur__Trol (COCI19_trol)C++20
50 / 50
1 ms328 KiB
#include <iostream>
#include <cstdint>

/* Test cases

 - 1 1 5
 + 15

 - 2 9 13 44 45
 + 19 17

 - 1 1998 2018
 + 102

 - 1 1 1152921504606846976
 + 5764607523034234920

*/

uint64_t calc(uint64_t x) {
    if(x == 0)
        return 0;
    if(x == 1)
        return 1;
    uint64_t y = (x-1)/9;
    y *= 45;
    x = x%9;
    if(x == 0)
        x = 9;
    y += x*(x+1)/2;
    return y;
}

int main() {
    
    int Q;
    std::cin >> Q;
    while(Q--) {
        uint64_t l, r;
        std::cin >> l >> r;
        std::cout << calc(r) - calc(l-1) << '\n';
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...