Submission #255743

# Submission time Handle Problem Language Result Execution time Memory
255743 2020-08-01T19:06:35 Z uacoder123 Trol (COCI19_trol) C++14
50 / 50
1 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
 
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli n;
  cin>>n;
  for(lli i=0;i<n;++i)
  {
    lli f,s,iif,iis,ans=0;
    cin>>f>>s;
    iif=f;
    iis=s;
    while(iif>9)
    {
      lli su=0;
      while(iif!=0)
      {
        su+=iif%10;
        iif/=10;
      }
      iif=su;
    }
    while(iis>9)
    {
      lli su=0;
      while(iis!=0)
      {
        su+=iis%10;
        iis/=10;
      }
      iis=su;
    }
    if(s-(iis-1)>=f)
      ans+=(iis+1)*(iis)/2;
    else
      ans+=(iis+iif)*(iis-iif+1)/2;
    if(9-iif+f<s)
      ans+=(9+iif)*(9-iif+1)/2;
    f=f+(9-iif)+1;
    s=s-(iis-1)-1;
    if(s>=f)
      ans+=(s-f+1)/9*45;
    cout<<ans<<endl;
  }
  return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct