結果

問題 No.681 Fractal Gravity Glue
ユーザー ei1333333ei1333333
提出日時 2018-04-28 00:13:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,390 bytes
コンパイル時間 2,094 ms
コンパイル使用メモリ 199,740 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 07:26:30
合計ジャッジ時間 3,382 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

int64 N, B, D;
int64 Dinv;

int64 f(int idx) {
  int64 base = 1;
  for(int i = 0; i < idx; i++) {
    base *= D + 1;
    if(base > mod) break;
  }
  return min(base - 1, 1LL << 30);
}


int64 mod_pow(int64 x, int64 n, int64 mod) {
  int64 ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}

// あー人生ね あー
int64 g(int idx) {
  int64 base = mod_pow(D + 1, idx + 1, mod);
  (base = mod - base) %= mod;
  base += D * idx % mod;
  base %= mod;
  base += D;
  base %= mod;
  base += 1;
  base %= mod;
  base *= Dinv;
  base %= mod;
  (base = mod - base) %= mod;
  return base;
}


int64 dfs(int idx, int pos) {
  if(pos == 0) return 0;
  if(idx == 1) return pos;
  int64 basesz = f(idx - 1) + 1;
  int64 sz = pos / basesz;
  if(sz == 0) { // basesz > pos
    int ok = 1, ng = idx;
    while(ng - ok > 1) {
      int mid = (ok + ng) / 2;
      if(f(mid - 1) + 1 /* basesz*/ <= pos) ok = mid;
      else ng = mid;
    }
    return dfs(ok, pos);
  }
  int64 ret = 1LL * sz * idx % mod;
  ret += g(idx - 1) * sz % mod;
  ret %= mod;
  ret += dfs(idx - 1, pos - sz * basesz) % mod;
  return ret % mod;
}


int main() {
  cin >> N >> B >> D;
  Dinv = mod_pow(D, mod - 2, mod);
  cout << (g(B) + mod - dfs(B, N)) % mod << endl;
}
0