Submission #1083931

#TimeUsernameProblemLanguageResultExecution timeMemory
1083931AliHasanliTrol (COCI19_trol)C++17
50 / 50
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; long long sum(long long a,long long b) { long long ans=0; for(long long i=a;i<=b;i++) { if(i%9==0)ans+=9; ans+=i%9; } return ans; } long long solve(long long a,long long b) { if(b-a<=20)return sum(a,b); long long a2=a,b2=b,ans=0; if(a%9!=1)a2+=(10-a%9); if(b%9!=0)b2-=b%9; //cout<<a2<<" "<<b2<<endl; ans+=sum(a,a2-1); ans+=sum(b2+1,b);//cout<<ans<<endl; ans+=(b2-a2+1)/9*45; return ans; } int main() { int t; cin>>t; while(t--) { long long a,b; cin>>a>>b; cout<<solve(a,b)<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...