結果
問題 | No.681 Fractal Gravity Glue |
ユーザー |
|
提出日時 | 2018-04-28 00:28:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,649 bytes |
コンパイル時間 | 1,849 ms |
コンパイル使用メモリ | 192,220 KB |
最終ジャッジ日時 | 2025-01-05 10:27:42 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using ld = long double; constexpr ll MOD = 1000000007LL; template <typename T> constexpr T INF = numeric_limits<T>::max() / 10; template <typename Functor> struct fix_type { Functor functor; template <typename... Args> decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); } }; template <typename Functor> fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; } ll N, B, D; ll DINV; ll power(const ll p, const ll n) { if (n == 0) { return 1; } if (n % 2 == 1) { return power(p, n - 1) * p % MOD; } else { const ll pp = power(p, n / 2); return pp * pp % MOD; } } ll stone(ll i) { return (((power(D + 1, i + 2) + MOD - 1) * DINV % MOD) + MOD - (i + 2)) % MOD; } int main() { cin >> N >> B >> D; DINV = power(D, MOD - 2); ll ans = 0; ll rest = N; while (rest > 0) { int ind = 0; ll H = D + 1; for (; H - 1 <= rest; ind++, H *= (D + 1)) { } if (ind == 0) { ans += rest; rest = 0; continue; } const ll h = H / (D + 1); const ll sub = (stone(ind - 1) + (ind + 1)) % MOD; const ll rep = rest / h; rest = rest % h; (ans += rep * sub % MOD) %= MOD; if (rest == h - 1) { (ans += stone(ind - 1)) %= MOD; rest = 0; } } cout << (stone(B - 1) + MOD - ans) % MOD << endl; return 0; }