답안 #377217

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377217 2021-03-13T11:48:56 Z OptxPrime Trol (COCI19_trol) C++11
50 / 50
1 ms 364 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>

using namespace std;

int f( long long x )
{
    if( x%9 != 0 ) return x%9;
    else return 9;
}

int main()
{
    long long q,l,r, suma;
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>l>>r;
        suma = 0;
        //cout << nadjiSumu(l,r)<<endl;
        long long brojBlokova = (r-l+1)/9;
        suma = brojBlokova*45;
        long long visak = (r-l+1)%9;
        if( visak!=0 ){
        long long zadnji = f(r);
        long long prvi = f(l);
        while( zadnji !=  prvi ){
            suma += zadnji;
            zadnji--;
            if( zadnji == 0 ) zadnji = 9;
        }
        suma += zadnji;
        }

        cout<<suma<<endl;
    }

return 0;
}





# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct