제출 #1248649

#제출 시각아이디문제언어결과실행 시간메모리
1248649hayyyTrol (COCI19_trol)C++20
50 / 50
0 ms328 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; // Count how many numbers from 1 to X have each digital root 1 to 9 vector<ll> count_droots_up_to(ll X) { vector<ll> counts(10, 0); // index 1-9 used ll full_cycles = X / 9; ll remainder = X % 9; for (int i = 1; i <= 9; ++i) { counts[i] = full_cycles; if (i <= remainder) counts[i]++; } return counts; } int main() { ll N; cin >> N; while (N--) { ll A, B; cin >> A >> B; vector<ll> cntB = count_droots_up_to(B); vector<ll> cntA = count_droots_up_to(A - 1); ll ans = 0; for (int i = 1; i <= 9; ++i) { ans += i * (cntB[i] - cntA[i]); } cout << ans << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...