제출 #1344325

#제출 시각아이디문제언어결과실행 시간메모리
1344325vuqar_bazarov1Trol (COCI19_trol)C++20
50 / 50
1 ms344 KiB
/*
* * author: attacker
* * created: 11.01.2026 11:28:45
*/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

#define mt_rng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int q;
  cin >> q;
  auto Cost = [&](int64_t num) {
    int64_t x = num;
    while (x >= 10) {
      int64_t s = 0;
      while (x > 0) {
        s += (x % 10);
        x /= 10;
      }
      x = s;
    }
    return x;
  };
  while (q--) {
    int64_t low, high;
    cin >> low >> high;
    int64_t sum = 0;
    int64_t cnt = high - low + 1;
    int64_t val = Cost(low);
    while (val != 1 && cnt > 0) {
      sum += val;
      val++;
      cnt--;
      if (val == 10) val = 1;
    }
    if (cnt >= 9) {
      sum += (cnt / 9) * 45;
      cnt = cnt % 9;
    }
    while (cnt--) {
      if (val == 10) {
        val = 1;
        sum += val;
      } else {
        sum += val;
      }
      ++val;
    }
    cout << sum << '\n';
  }
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...