Submission #344811

#TimeUsernameProblemLanguageResultExecution timeMemory
344811Pichon5Trol (COCI19_trol)C++17
50 / 50
1 ms364 KiB
#include<bits/stdc++.h> #define lcm(a,b) (a/__gcd(a,b))*b #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long int #define vi vector<int> #define vll vector<ll> #define pb push_back #define F first #define S second #define mp make_pair //salida rapida "\n" //DECIMALES fixed<<sp(n)<<x<<endl; //gcd(a,b)= ax + by //lCB x&-x //set.erase(it) - ersases the element present at the required index//auto it = s.find(element) //set.find(element) - iterator pointing to the given element if it is present else return pointer pointing to set.end() //set.lower_bound(element) - iterator pointing to element greater than or equal to the given element //set.upper_bound(element) - iterator pointing to element greater than the given element // | ^ using namespace std; ll f(ll num){ while(num>9){ ll aux=num; ll sum=0; while(aux>0){ sum+=aux%10; aux/=10; } num=sum; } return num; } int main() { ll q,l,r; cin>>q; while(q--){ cin>>l>>r; ll c=r-l+1; //c es la cantida de numeros que tengo que sumar ll in=f(l); if(in+c-1<10){ cout<<(in+in+c-1)*(c)/2<<endl; continue; } ll res=(in+9)*(9-in+1)/2; c-=(9-in+1); res+=(c/9)*45; c=c%9; res+=(1+c)*c/2; cout<<res<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...