답안 #976665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
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';
    }
}
# 결과 실행 시간 메모리 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