Submission #20324701


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string X; cin >> X;
  ll M; cin >> M;

  ll N = X.size();
  if (N == 1) {
    cout << 1 << '\n';
    return 0;
  }

  vector<ll> d(60, 0);
  ll MAX = 0;
  for (ll i = 0; i < N; i++) {
    d[i] = X[i] - '0';
    MAX = max(MAX, d[i]);
  }

  ll l = MAX;
  ll r = 1e18 + 1;
  while (l < r - 1) {
    ll m = (l + r) / 2;

    bool ok = true;
    ll M2 = M;
    ll M3 = M2;
    for (ll i = 0; i < N; i++) {
      ll temp = 1;
      M3 = M2;
      for (ll j = 0; j < N - 1 - i; j++) {
        M2 /= m;
        temp *= m;
      }
      if (d[i] < M2) {
        ok = true;
        break;
      } else if (d[i] > M2) {
        ok = false;
        break;
      } else {
        M2 = M3 - temp * d[i];
      }
    }
    if (ok) l = m;
    else r = m;
  }

  ll ans = l - MAX;
  cout << ans << '\n';
  return 0;
}

Submission Info

Submission Time
Task D - Base n
User nakaken88
Language C++ (GCC 9.2.1)
Score 0
Code Size 987 Byte
Status WA
Exec Time 8 ms
Memory 3632 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 40
WA × 7
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, one_digit_01.txt, one_digit_02.txt, one_digit_03.txt, one_digit_04.txt, one_digit_05.txt, one_digit_06.txt, one_digit_07.txt, one_digit_08.txt, one_digit_09.txt, one_digit_10.txt, one_digit_11.txt, one_digit_12.txt, one_digit_13.txt, one_digit_14.txt, one_digit_15.txt, one_digit_16.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 8 ms 3576 KiB
hand_02.txt WA 2 ms 3580 KiB
hand_03.txt AC 2 ms 3580 KiB
hand_04.txt AC 2 ms 3568 KiB
one_digit_01.txt AC 2 ms 3608 KiB
one_digit_02.txt WA 2 ms 3488 KiB
one_digit_03.txt WA 2 ms 3504 KiB
one_digit_04.txt WA 2 ms 3556 KiB
one_digit_05.txt AC 3 ms 3504 KiB
one_digit_06.txt AC 2 ms 3508 KiB
one_digit_07.txt WA 3 ms 3448 KiB
one_digit_08.txt WA 3 ms 3492 KiB
one_digit_09.txt AC 2 ms 3576 KiB
one_digit_10.txt AC 2 ms 3572 KiB
one_digit_11.txt AC 2 ms 3568 KiB
one_digit_12.txt WA 2 ms 3508 KiB
one_digit_13.txt AC 3 ms 3616 KiB
one_digit_14.txt AC 2 ms 3628 KiB
one_digit_15.txt AC 2 ms 3608 KiB
one_digit_16.txt AC 2 ms 3556 KiB
random_01.txt AC 3 ms 3616 KiB
random_02.txt AC 2 ms 3560 KiB
random_03.txt AC 2 ms 3628 KiB
random_04.txt AC 2 ms 3616 KiB
random_05.txt AC 3 ms 3556 KiB
random_06.txt AC 2 ms 3620 KiB
random_07.txt AC 2 ms 3564 KiB
random_08.txt AC 2 ms 3620 KiB
random_09.txt AC 3 ms 3440 KiB
random_10.txt AC 2 ms 3452 KiB
random_11.txt AC 2 ms 3632 KiB
random_12.txt AC 2 ms 3616 KiB
random_13.txt AC 3 ms 3552 KiB
random_14.txt AC 2 ms 3564 KiB
random_15.txt AC 2 ms 3604 KiB
random_16.txt AC 2 ms 3604 KiB
random_17.txt AC 2 ms 3628 KiB
random_18.txt AC 2 ms 3600 KiB
random_19.txt AC 5 ms 3564 KiB
random_20.txt AC 2 ms 3628 KiB
random_21.txt AC 2 ms 3556 KiB
random_22.txt AC 3 ms 3564 KiB
random_23.txt AC 2 ms 3616 KiB
random_24.txt AC 2 ms 3616 KiB
sample_01.txt AC 2 ms 3556 KiB
sample_02.txt AC 2 ms 3456 KiB
sample_03.txt AC 2 ms 3616 KiB