답안 #838198

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838198 2023-08-26T10:17:15 Z LinkedArray Trol (COCI19_trol) C++17
50 / 50
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long q, l, r, d, repeating, cif, sum;

    cin >> q;
    while(q--){
        cin >> l >> r;

        sum = 0;

        while(l % 9 != 1) sum += (l++ - 1 + 9) % 9 + 1;
        while(r % 9 != 0) sum += (r-- - 1 + 9) % 9 + 1;
        cout << sum + 5 * (r - l + 1) << '\n';

        /* sum = 0;
        repeating = (r - l + 1) / 9;

        cif = (l - 1 + 9) % 9 + 1; // Cifra de control al numarului L
        if(cif != 1){ // Cat timp nu este egala cu 1
            sum += 45 - ((cif - 1) * cif / 2); // Adun la suma pana la 1
        }

        sum += 5 * repeating; // Cifrele de control se repeta: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 .....

        cif = (r - 1 + 9) % 9 + 1; // Cifra de control al numarului R
        if(cif != 9){ // Cat timp nu este egala cu 9
            sum += cif * (cif + 1) / 2; // Adunam la suma
        } */
    }


    return 0;
}

Compilation message

trol.cpp: In function 'int main()':
trol.cpp:5:24: warning: unused variable 'd' [-Wunused-variable]
    5 |     long long q, l, r, d, repeating, cif, sum;
      |                        ^
trol.cpp:5:27: warning: unused variable 'repeating' [-Wunused-variable]
    5 |     long long q, l, r, d, repeating, cif, sum;
      |                           ^~~~~~~~~
trol.cpp:5:38: warning: unused variable 'cif' [-Wunused-variable]
    5 |     long long q, l, r, d, repeating, cif, sum;
      |                                      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct