Submission #725408

# Submission time Handle Problem Language Result Execution time Memory
725408 2023-04-17T11:26:55 Z TheSahib Trol (COCI19_trol) C++17
10 / 50
1 ms 304 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 += (r - l + 3) / 10 * 10 * 9 / 2;
        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Incorrect 1 ms 304 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 1 ms 212 KB Output isn't correct