結果

問題 No.681 Fractal Gravity Glue
コンテスト
ユーザー vjudge1
提出日時 2025-11-16 12:18:47
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,132 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 160,268 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-16 12:18:49
合計ジャッジ時間 2,508 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int mod = 1e9 + 7;
int len[100];

inline int ksm(int a, int b, int mod)
{
    int res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1ll;
    }
    return res;
}
inline int solve(int i, int d)
{
    return ((d + 1) % mod * (ksm(d + 1, i, mod) - 1) % mod * ksm(d, mod - 2, mod) % mod - i + mod) % mod;
}
inline int solve2(int i, int n, int d)
{
    if (!n)
        return 0;
    int tmp = n / (1 + len[i - 1]);
    int sum = tmp % mod * ((i + solve(i - 1, d)) % mod) % mod;
    (sum += solve2(i - 1, n % (1 + len[i - 1]), d)) %= mod;
    return sum;
}
signed main()
{

 
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, b, d;
    cin >> n >> b >> d;
    len[1] = d;
    int x;
    for (int i = 2;; i++)
    {
        len[i] = d + len[i - 1] * (d + 1);
        if (len[i] > n)
        {
            x = i;
            break;
        }
    }
    int res = solve(b, d), sum = solve2(x, n, d);
    res = ((res - sum) % mod + mod) % mod;
    cout << res;
}
0