提出 #46440363


ソースコード 拡げる

/*
Author : Hocky Yudhiono
Sel 10 Okt 2023 10:17:32
*/

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

typedef long long ll;
typedef long long LL;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<ll, ll> PLL;
typedef pair<ll, ll> pll;
typedef long double ld;

#define rep(i, a, b) for(LL i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define popf pop_front
#define pf push_front
#define popb pop_back
#define pb push_back
#define fi first
#define se second

const double EPS = 1e-9;
const int INFMEM = 63;

// Do dir^1 to get reverse direction
const int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
const int dy[8] = {1, -1, 0, 0, 1, -1, -1, 1};
const char dch[4] = {'R', 'L', 'D', 'U'};

// Do (dir + 2)%4 to get reverse direction
// const int dx[8] = {-1,0,1,0,-1,1,1,-1};
// const int dy[8] = {0,1,0,-1,1,1,-1,-1};
// const char dch[4] = {'U','R','D','L'};
const double PI = 3.141592653589793;

inline void fasterios() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
}
#define endl '\n'
const int MOD = 998244353;

template<int MOD>
class ModInt {
 public:
  int v;

  ModInt() : v(0) {}
  ModInt(long long _v) {
    v = int((-MOD < _v && _v < MOD) ? (_v) : (_v % MOD));
    if (v < 0) v += MOD;
  }

  friend bool operator==(const ModInt &a, const ModInt &b) { return a.v == b.v; }
  friend bool operator!=(const ModInt &a, const ModInt &b) { return a.v != b.v; }
  friend bool operator<(const ModInt &a, const ModInt &b) { return a.v < b.v; }
  friend bool operator<=(const ModInt &a, const ModInt &b) { return a.v <= b.v; }
  friend bool operator>(const ModInt &a, const ModInt &b) { return a.v > b.v; }
  friend bool operator>=(const ModInt &a, const ModInt &b) { return a.v >= b.v; }

  ModInt& operator+=(const ModInt &a) {
    if ((v += a.v) >= MOD) v -= MOD;
    return *this;
  }
  ModInt& operator-=(const ModInt &a) {
    if ((v -= a.v) < 0) v += MOD;
    return *this;
  }
  ModInt& operator*=(const ModInt &a) {
    v = 1ll * v * a.v % MOD;
    return *this;
  }
  ModInt& operator/=(const ModInt &a) {
    return (*this) *= inverse(a);
  }

  friend ModInt pow(ModInt a, long long x) {
    ModInt res = 1; assert(x >= 0);
    for (; x; x /= 2, a *= a) if (x & 1) res *= a;
    return res;
  }
  friend ModInt inverse(ModInt a) {
    assert(a.v != 0);
    return pow(a, MOD - 2);
  }

  ModInt operator+() const { return ModInt(v); }
  ModInt operator-() const { return ModInt(-v); }
  ModInt operator++() const { return *this += 1; }
  ModInt operator--() const { return *this -= 1; }

  friend ModInt operator+(ModInt a, const ModInt &b) { return a += b; }
  friend ModInt operator-(ModInt a, const ModInt &b) { return a -= b; }
  friend ModInt operator*(ModInt a, const ModInt &b) { return a *= b; }
  friend ModInt operator/(ModInt a, const ModInt &b) { return a /= b; }

  friend istream& operator>>(istream &is, ModInt &v) { is >> v.v; return is; }
  friend ostream& operator<<(ostream &os, const ModInt &v) { os << v.v; return os; }
};

using Mint = ModInt<MOD>;

LL n;

LL expo(LL a, LL b, LL MODULO = (1LL << 63)) {
  // a %= MOD; // USE THIS WHEN N IS REALLY BIG!
  LL ret = 1;
  while (b > 0) {
    if (b & 1) ret = (ret * a) % MODULO;
    a = (a * a) % MODULO; b >>= 1;
  }
  return ret;
}

Mint dfs2(LL pos, LL rem, LL a, LL b) {
  int until = min(min(9LL, a - 1), b - 1);
  if (pos == 0) {
    if (rem != 0) return 0;
    return until + 1;
  }
  LL selisih = expo(a, pos) - expo(b, pos);
  Mint ret = 0;
  for (LL i = 0; i <= until; i++) {
    if (rem < i * selisih) break;
    ret += dfs2(pos - 1, rem - i * selisih, a, b);
  }
  // cout << pos << " " << rem << " " << a << " " << b << endl;
  // cout << "Return dfs2 " << ret << endl;
  return ret;
}

Mint dfs(LL pos, LL rem) {
  Mint ret = 0;
  for (LL a = 3; a <= n; a++) {
    if (expo(a, pos) - expo(a - 1, pos) > rem) break;
    for (LL b = a - 1; b >= 2; b--) {
      LL selisih = expo(a, pos) - expo(b, pos);
      if (selisih > rem) break;
      LL until = min(min(9LL, a - 1), b - 1);
      // cout << a << " " << b << " " << rem << " " << pos << " " << selisih << " " << until << endl;
      for (LL i = 1; i <= until; i++) {
        if (rem < i * selisih) break;
        ret += dfs2(pos - 1, rem - i * selisih, a, b);
      }
    }
  }
  // cout << "Return " << ret << endl;
  return ret;
}

int main() {
  fasterios();
  LL x; cin >> n >> x;
  // Cari yang satu pair
  // k = 1
  Mint ans = 0;
  // cari faktor dari x
  for (int i = 1; i < 10; i++) {
    if (x % i) continue;
    LL selisih = x / i;
    // cout << selisih << endl;
    const LL LIM = 200100;
    LL curans = 0;
    for (int a = 2; a <= min(LIM, n); a++) {
      int b = a - selisih;
      if (a <= 0) continue;
      if (i >= b || i >= a || i >= n) continue;
      curans += min(min(a, b), 10);
    }
    ans += curans;
    LL kiri = LIM + 1;
    LL kanan = n;
    if (kiri <= kanan) {
      ans += Mint((kanan - kiri + 1) * 10);
    }
  }
  // cout << ans << endl;
  // return 0;
  // cout << "k = 1 " << ans << endl;
  // ans = 0;
  // Cari yang dua pangkat
  for (int i = 2; i <= 12; i++) {
    ans += dfs(i, x);
    // cout << "k = i " << i << " " << ans << endl;
  }
  cout << ans << endl;
}

提出情報

提出日時
問題 G - Two Kinds of Base
ユーザ hocky
言語 C++ 20 (gcc 12.2)
得点 600
コード長 5553 Byte
結果 AC
実行時間 69 ms
メモリ 3640 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 48
セット名 テストケース
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3600 KiB
example_01.txt AC 1 ms 3520 KiB
example_02.txt AC 69 ms 3416 KiB
test_00.txt AC 34 ms 3516 KiB
test_01.txt AC 36 ms 3516 KiB
test_02.txt AC 24 ms 3448 KiB
test_03.txt AC 18 ms 3516 KiB
test_04.txt AC 53 ms 3608 KiB
test_05.txt AC 23 ms 3388 KiB
test_06.txt AC 37 ms 3480 KiB
test_07.txt AC 7 ms 3520 KiB
test_08.txt AC 67 ms 3576 KiB
test_09.txt AC 19 ms 3576 KiB
test_10.txt AC 57 ms 3520 KiB
test_11.txt AC 38 ms 3580 KiB
test_12.txt AC 52 ms 3412 KiB
test_13.txt AC 59 ms 3412 KiB
test_14.txt AC 28 ms 3520 KiB
test_15.txt AC 31 ms 3640 KiB
test_16.txt AC 4 ms 3524 KiB
test_17.txt AC 35 ms 3460 KiB
test_18.txt AC 14 ms 3476 KiB
test_19.txt AC 24 ms 3452 KiB
test_20.txt AC 68 ms 3516 KiB
test_21.txt AC 69 ms 3524 KiB
test_22.txt AC 68 ms 3608 KiB
test_23.txt AC 68 ms 3520 KiB
test_24.txt AC 69 ms 3416 KiB
test_25.txt AC 67 ms 3576 KiB
test_26.txt AC 68 ms 3640 KiB
test_27.txt AC 68 ms 3436 KiB
test_28.txt AC 68 ms 3604 KiB
test_29.txt AC 69 ms 3392 KiB
test_30.txt AC 1 ms 3448 KiB
test_31.txt AC 1 ms 3560 KiB
test_32.txt AC 1 ms 3516 KiB
test_33.txt AC 1 ms 3512 KiB
test_34.txt AC 1 ms 3604 KiB
test_35.txt AC 1 ms 3520 KiB
test_36.txt AC 1 ms 3516 KiB
test_37.txt AC 1 ms 3476 KiB
test_38.txt AC 1 ms 3576 KiB
test_39.txt AC 1 ms 3452 KiB
test_40.txt AC 1 ms 3416 KiB
test_41.txt AC 58 ms 3516 KiB
test_42.txt AC 58 ms 3412 KiB
test_43.txt AC 58 ms 3436 KiB
test_44.txt AC 58 ms 3516 KiB