# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
245275 | Ort | Trol (COCI19_trol) | C11 | 5 ms | 352 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<stdio.h>
#define ll long long
int t, i, j;
ll f, s;
ll arr[17] = {83385908498332845, 9265100944259205,1029455660473245, 114383962274805, 12709329141645, 1412147682405, 156905298045, 17433922005, 1937102445, 215233605, 23914845, 2657205, 295245, 32805, 3645, 405, 45};
ll fpow(ll a, ll b) {
ll res = 1;
while(b>0) {
if(b&1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
ll solve(ll a) {
ll n = 18;
ll sol = 0;
ll d;
for(j=0;j<17;j++) {
d = fpow(9, n-j-1);
while(a>=d) {
sol += arr[j];
a -= d;
}
}
sol += ((a*(a+1))>>1);
return sol;
}
int main() {
scanf("%d", &t);
for(i=0;i<t;i++) {
scanf("%lld%lld", &f, &s);
printf("%lld\n", solve(s)-solve(f-1));
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |