# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
206610 | stefdasca | Trol (COCI19_trol) | C++14 | 5 ms | 376 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |