답안 #975154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975154 2024-05-04T13:52:19 Z vjudge1 Trol (COCI19_trol) C++17
50 / 50
1 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll digits ( ll y ){
    ll sum = 1e18;

    while ( sum >= 10 ){
        sum = 0;
        while ( y >= 1 ){
            sum += (y % 10);
            y /= 10;
        }
        y = sum;
    }

    return sum;
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int q; cin >> q;
    while ( q-- ){
        ll l, r; cin >> l >> r;

        ll now = l;

        ll ans = 0;

        while ( now <= r && digits ( now ) != 1 ){
            ans += digits ( now );
            now++;
        }

        ll temp = ( ( r - ( now - 1)) / 9 );

        ans += ( temp * 45ll);

        now += ( temp * 9);

        for ( ll i = now; i <= r; i++){
            ans += digits(i);
        }

        cout << ans << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct