#include #define int long long using namespace std; int mod = 1000000007; int power(int a, int n) { if (n == 0) return 1; if (n & 1) return (a * power(a, n - 1)); return power(a * a, n / 2); } int powmod(int a, int n, int mod) { if (n == 0) return 1; if (n & 1) return (a * powmod(a, n - 1, mod)) % mod; return powmod((a * a) % mod, n / 2, mod); } int fs(int b, int d) { int res = (d + 1) * (powmod(d + 1, b, mod) + mod - 1) % mod * powmod(d, mod - 2, mod) % mod; return (res + mod - b) % mod; } int fn(int b, int d) { return power(d + 1, b) - 1; } int n, b, d; signed main() { int i; cin >> n >> b >> d; int ans = fs(b, d); for (i = 0; fn(i, d) <= n; i++); i--; for (; i >= 0; i--) { int res = power(d + 1, i); int syo = n / res; int hiku = syo * (fs(i, d) + i + 1) % mod; ans = (ans + mod - hiku) % mod; n %= res; } cout << ans << endl; return 0; }