Submission #245275

#TimeUsernameProblemLanguageResultExecution timeMemory
245275OrtTrol (COCI19_trol)C11
50 / 50
5 ms352 KiB
#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)

trol.c: In function 'main':
trol.c:36:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &t);
     ^~~~~~~~~~~~~~~
trol.c:38:6: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
      scanf("%lld%lld", &f, &s);
      ^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...