結果

問題 No.681 Fractal Gravity Glue
ユーザー ei1333333ei1333333
提出日時 2018-04-28 00:09:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,139 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 198,432 KB
実行使用メモリ 531,268 KB
最終ジャッジ日時 2023-09-10 07:10:23
合計ジャッジ時間 6,179 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

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

int64 N, B, D;

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 *= mod_pow(D, mod - 2, mod);
  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;
  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;
  cout << (g(B) + mod - dfs(B, N)) % mod << endl;
}
0