답안 #727718

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727718 2023-04-21T07:25:13 Z ilhan_arda Trol (COCI19_trol) C++17
50 / 50
1 ms 212 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fi first
#define se second
#define pb push_back
#define int long long
using namespace std;
typedef long long ll;
typedef tuple<int, int, int> iii;


int t=1+2+3+4+5+6+7+8+9;

int mod(int x){
	int r= x%9;
	if(!r)r=9;
	return r;
}

int32_t main(){
	int q;
	cin>>q;
	while(q--){
		int l, r;
		cin>>l>>r;
		int ans=0;
		bool c=false;
		for(int i=mod(l);i<=9;i++){
			ans+=i;
			if(l+(i-l%9)==r){
				c=true;
				break;
			}
		}
		if(c){
			cout<<ans<<endl;
			continue;
		}
		l+=9-mod(l)+1;
		for(int i=1;i<=r%9;i++){
			ans+=i;
		}
		r-=r%9;
		ans+=(r-l+1)/9*t;
		cout<<ans<<endl;
	}
}


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