#include using namespace std; using ll = long long; const ll MOD = 1000000007; ll modpow(ll x, ll n, ll mod = MOD) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll calc(int i, int d) { ll tmp = modpow(d + 1, i - 1); ll res = (tmp + MOD - 1) % MOD * modpow(d, MOD - 2) % MOD; (res += tmp * (d + 2) % MOD) %= MOD; (res += (MOD - i - 1)) %= MOD; return res; } ll G[50], N[50]; ll solve(int idx, ll num) { if (idx == 0) return 0; ll mod = num % (N[idx - 1] + 1); if (mod == 0) { return (G[idx - 1] + idx) * (num / (N[idx - 1] + 1)) % MOD; } else if (mod == N[idx - 1]) { return ((G[idx - 1] + idx) * (num / (N[idx - 1] + 1)) % MOD + G[idx - 1]) % MOD; } else { return ((G[idx - 1] + idx) * (num / (N[idx - 1] + 1)) % MOD + solve(idx - 1, mod)) % MOD; } } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, b, d; cin >> n >> b >> d; int lim = 0; N[0] = 1; for (int i = 0; ; i++) { if (N[i] - 1 > n) { N[i]--; break; } lim++; N[i + 1] = N[i] * (d + 1); N[i]--; } for (int i = 1; i < lim; i++) { G[i] = calc(i, d); } ll ans = calc(b, d); (ans += MOD - solve(lim, n)) %= MOD; cout << ans << endl; return 0; }