# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
485717 | tato | Trol (COCI19_trol) | C++14 | 1 ms | 204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll back(ll a)
{
ll cnt=0;
while(a>0)
{
cnt+=(a%10);
a=a/10;
}
if(cnt>9)
return back(cnt);
else
return cnt;
}
int main()
{
int t;
cin>>t;
int b[12];
b[0]=0;
for(int i=1; i<=11; i++)
b[i]=b[i-1]+i;
while(t--)
{
ll l,r;
cin>>l>>r;
ll cnt=0;
ll pas=0;
ll x=r-l;
cnt=back(l);
if(x<=9)
{
for(ll i=l; i<=r; i++)
pas+=(back(i));
}
else
{
pas=b[9]-b[cnt-1];
x-=(9-cnt);
pas+=(45*(x/9)+b[x%9]);
}
cout<<pas<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |