Submission #209325

#TimeUsernameProblemLanguageResultExecution timeMemory
209325papaTrol (COCI19_trol)C++14
20 / 50
5 ms376 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int q; ll l,r; //caka je u tome sto je taj niz periodican //jer suma cifara daje isti ostatak kao i sam taj broj //pa ce onda redom da budu 1,2,3,4,5,6,7,8,9,1... //pronadjemo granice i onda samo vidimo koliko se takvih intervala pojavljuje int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> q; while(q--) { cin >> l >> r; ll sol = 0; if(r-l<=20) { for(ll i=l;i<=r;i++) sol = sol + (i%9==0) ? 9 : i%9; cout << sol << "\n"; } else { while(1) { if((l%9)==1) break; else { sol+=((l%9)==0) ? 9 : (l%9); l++; } } while(1) { if((r%9)==0) break; else { sol+=(r%9); r--; } } ll cnt = r-l+1; sol+=cnt*5; cout << sol << "\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...