답안 #725410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725410 2023-04-17T11:30:06 Z TheSahib Trol (COCI19_trol) C++17
50 / 50
1 ms 212 KB
#include <bits/stdc++.h>
 
#pragma GCC optimize("O3")
 
#define ll long long
#define pii pair<ll, ll>
 
using namespace std;

ll f(ll a){
    ll ans = 0;
    while(a){
        ans += a % 10;
        a /= 10;
    }
    return ans;
}

int main(){
    int q; cin >> q;
    while(q--){
        ll l, r; cin >> l >> r;
        ll l1 = l;
        while(l1 != f(l1)){
            l1 = f(l1);
        }
        ll r1 = r;
        while(r1 != f(r1)){
            r1 = f(r1);
        }
        ll ans = 0;
        while(l1 != 1 && l <= r){
            ans += l1;
            l1++;
            if(l1 == 10) l1 = 1;
            l++;
        }
        while(r1 != 9 && l <= r){
            ans += r1;
            r1--;
            if(r1 == 0) r1 = 9;
            r--;
        }
        ans += (1ll * (r - l + 1) / 9) * 10 * 9 / 2;
        cout << ans << '\n';
    }
}
# 결과 실행 시간 메모리 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