Submission #245275

# Submission time Handle Problem Language Result Execution time Memory
245275 2020-07-05T22:26:16 Z Ort Trol (COCI19_trol) C
50 / 50
5 ms 352 KB
#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

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 time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 352 KB Output is correct
5 Correct 5 ms 256 KB Output is correct