結果

問題 No.681 Fractal Gravity Glue
ユーザー PachicobuePachicobue
提出日時 2018-04-28 00:28:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,649 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 198,492 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 07:35:58
合計ジャッジ時間 2,991 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0