제출 #1240319

#제출 시각아이디문제언어결과실행 시간메모리
1240319themoonTrol (COCI19_trol)C++20
50 / 50
1 ms328 KiB
#include <bits/stdc++.h>
#define int long long
#define bismillah ios_base::sync_with_stdio(false);
using namespace std;

int digital_root(int x){
    return x == 0 ? 0 : (x - 1) % 9 + 1;
}

signed main(){
    bismillah;
    int q;
    cin >> q;
    while(q--){
        long long L, R;
        cin >> L >> R;
        long long len = R - L + 1;
        int start = digital_root(L);
        long long total = 0;

        long long full = len / 9;
        total += full * 45;

        long long rem = len % 9;
        for(int i = 0; i < rem; i++){
            total += (start + i - 1) % 9 + 1;
        }

        cout << total << endl;
    }
}

#Verdict Execution timeMemoryGrader output
Fetching results...