Submission #206610

# Submission time Handle Problem Language Result Execution time Memory
206610 2020-03-04T08:37:36 Z stefdasca Trol (COCI19_trol) C++14
50 / 50
5 ms 376 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007

using namespace std;

typedef long long ll;


int add(int a, int b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

int q;
unsigned long long a, b, ans;
int controldigit(unsigned long long a)
{
    int x = 0;
    while(a)
    {
        x += a%10;
        a /= 10;
    }
    x %= 9;
    if(x == 0)
        return 9;
    return x;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> q;
    for(int i = 1; i <= q; ++i)
    {
        cin >> a >> b;
        ans = 0;
        while(a <= b && controldigit(a) != 1)
            ans += controldigit(a), ++a;
        while(a <= b && controldigit(b) != 9)
            ans += controldigit(b), --b;
        unsigned long long dif = b - a + 1;
        ans = ans + (dif / 9) * 45;
        cout << ans << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct