Submission #691878

#TimeUsernameProblemLanguageResultExecution timeMemory
691878delreyTrol (COCI19_trol)C++14
50 / 50
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; int long Sum(int l, int r) { int ret = 0; for(int i = l; i <= r; i++) ret += i; return ret; } int main() { int q; long long a, b; cin>>q; int sum9 = Sum(1, 9); while(q--) { cin>>a>>b; long long x = a, y = b, res = 0; if(y - x < 20) { for(long long i = x; i <= y; i++) { res += i % 9; if(i % 9 == 0) res += 9; } cout<<res<<endl; continue; } if(a % 9) { x += 9 - (x % 9); res += Sum(a % 9, 9); } if(b % 9) { y -= y % 9; res += Sum(1, b % 9); } if(a == x) res += 9; res += (y - x) / 9 * sum9; //cout<<x<<" "<<y<<" "; cout<<res<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...