답안 #977162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977162 2024-05-07T12:46:35 Z vjudge1 Trol (COCI19_trol) C++11
30 / 50
1000 ms 600 KB
#include <bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int dig(ll i){
   
    while(i>9){
        ll nilai=i, jdg=0;
        while(nilai!=0){
            jdg+=nilai%10;
            nilai/=10;
        }
       
        i= jdg;
    }
    return i;
    
}

int jumlah(ll p,ll r){
    ll jum=0;
    for(ll i=p; i<= r; i++){
        jum+=dig(i);
    }
    return jum;
}


int main(){
    ll q;
    cin>>q;
    
    while(q--){
        ll p, r;
        cin>>p>>r;
        cout<<jumlah(p, r)<<endl;
    }
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Execution timed out 1092 ms 408 KB Time limit exceeded
5 Execution timed out 1026 ms 344 KB Time limit exceeded