#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define bit(n) (1LL<<(n)) #define sz(x) ((int)(x).size()) #define TEN(n) ((ll)(1e##n)) #define fst first #define snd second string DBG_DLM(int &i){return(i++==0?"":", ");} #define DBG_B(exp){int i=0;os<<"{";{exp;}os<<"}";return os;} templateostream&operator<<(ostream&os,vectorv); templateostream&operator<<(ostream&os,setv); templateostream&operator<<(ostream&os,queueq); templateostream&operator<<(ostream&os,priority_queueq); templateostream&operator<<(ostream&os,pairp); templateostream&operator<<(ostream&os,mapmp); templateostream&operator<<(ostream&os,unordered_mapmp); templatevoid DBG(ostream&os,TPL t){} templatevoid DBG(ostream&os,TPL t){os<<(I==0?"":", ")<(t);DBG(os,t);} templatevoid DBG(ostream&os,pairp,string delim){os<<"("<ostream&operator<<(ostream&os,tuplet){os<<"(";DBG<0,tuple,Ts...>(os,t);os<<")";return os;} templateostream&operator<<(ostream&os,pairp){DBG(os,p,", ");return os;} templateostream&operator<<(ostream&os,vectorv){DBG_B(forr(t,v){os<ostream&operator<<(ostream&os,sets){DBG_B(forr(t,s){os<ostream&operator<<(ostream&os,queueq){DBG_B(for(;q.size();q.pop()){os<ostream&operator<<(ostream&os,priority_queueq){DBG_B(for(;q.size();q.pop()){os<ostream&operator<<(ostream&os,mapm){DBG_B(forr(p,m){os<");});} templateostream&operator<<(ostream&os,unordered_mapm){DBG_B(forr(p,m){os<");});} #define DBG_OVERLOAD(_1,_2,_3,_4,_5,_6,macro_name,...)macro_name #define DBG_LINE(){char s[99];sprintf(s,"line:%3d | ",__LINE__);cerr<;using pll=pair;using pil=pair;using pli=pair; using vs=vector;using vvs=vector;using vvvs=vector; using vb=vector;using vvb=vector;using vvvb=vector; using vi=vector;using vvi=vector;using vvvi=vector; using vl=vector;using vvl=vector;using vvvl=vector; using vd=vector;using vvd=vector;using vvvd=vector; using vpii=vector;using vvpii=vector;using vvvpii=vector; templatebool amax(A&a,const B&b){return b>a?a=b,1:0;} templatebool amin(A&a,const B&b){return b>l;return l;} string rs(){string s;cin>>s;return s;} const int mod = 1e9+7; template struct Mint { int x; Mint() : x(0) {} Mint(int y) : x(y >= 0 ? y % MOD : MOD - (-y) % MOD) {} Mint(long long sll) : x(sll % MOD) { if (x < 0) x += MOD; } Mint &operator+=(const Mint &rhs){ if((x += rhs.x) >= MOD) x -= MOD; return *this; } Mint &operator-=(const Mint &rhs){ if((x += MOD - rhs.x) >= MOD) x -= MOD; return *this; } Mint &operator*=(const Mint &rhs){ x = 1LL*x*rhs.x % MOD; return *this; } Mint &operator/=(const Mint &rhs){ x = (1LL*x*rhs.inv().x) % MOD; return *this; } Mint operator-() const { return Mint(-x); } Mint operator+(const Mint &rhs) const { return Mint(*this) += rhs; } Mint operator-(const Mint &rhs) const { return Mint(*this) -= rhs; } Mint operator*(const Mint &rhs) const { return Mint(*this) *= rhs; } Mint operator/(const Mint &rhs) const { return Mint(*this) /= rhs; } bool operator<(const Mint &rhs) const { return x < rhs.x; } Mint inv() const { assert(x != 0); signed a = x, b = MOD, u = 1, v = 0, t; while (b) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return Mint(u); } Mint operator^(uint64_t t) const { Mint e = *this, res = 1; for(; t; e *= e, t>>=1) if (t & 1) res *= e; return res; } }; template ostream &operator<<(ostream &os, const Mint &rhs) { return os << rhs.x; } template istream &operator>>(istream &is, Mint &rhs) { int64_t s; is >> s; rhs = Mint(s); return is; }; using mint = Mint; using vm=vector;using vvm=vector;using vvvm=vector; template struct matrix_ { array val; matrix_(vector> ini) { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) val[i * N + j] = ini[i][j]; } matrix_(int d = 0) { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) val[i * N + j] = T((i == j) * d); } matrix_ operator+(const matrix_ &x) const { matrix_ ret; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { ret.val[i * N + j] = val[i * N + j] + x.val[i * N + j]; } return ret; } matrix_ operator*(const matrix_ &x) const { matrix_ ret; for (int i = 0; i < N; i++) for (int k = 0; k < N; k++) for (int j = 0; j < N; j++) { ret.val[i * N + j] += val[i * N + k] * x.val[k * N + j]; } return ret; } vector operator*(const vector &v) const { vector ret(N); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { ret[i] += val[i * N + j] * v[j]; } return ret; } matrix_ operator^(unsigned long long p) const { matrix_ ret(1); matrix_ x(*this); while (p) { if (p & 1) ret = ret * x; x = x * x; p >>= 1; } return ret; } T& at(int row, int col) { return val[row * N + col]; } const T& at(int row, int col) const { return val[row * N + col]; } }; template ostream& operator<<(ostream& os, const matrix_& mat) { vector> vec(N, vector(N)); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) vec[i][j] = mat.at(i, j); os << vec; return os; } using Mat3 = matrix_; mint volume(int b, int d) { Mat3 mat({{d+1,d,0}, {0,1,1}, {0,0,1}}); mat = mat ^ (b+1); return mat.at(0, 2); } const ll inf = 1e9+7; mint solve() { int n = ri(), b = ri(), d = ri(); out(n,b,d); mint total_volume = volume(b, d); out(total_volume); vl counts(1); rep(i, 1, b+1) { ll nex = counts[i-1] * (d+1) + d; if (nex >= mod) break; counts.emplace_back(nex); } auto cnt = [&](int b) { if (b >= sz(counts)) return inf; return counts[b]; }; out(counts); mint removal; int c = sz(counts); for (; n; c--) { out(n, c); int cp = cnt(c-1); if (cp > n) { continue; } int c2 = n / (cp+1); removal += volume(c-1, d) * c2; removal += c * c2; n -= (cp+1) * c2; } mint ans = total_volume - removal; out(total_volume, removal, ans); return ans; } void Main() { cout << solve() << endl; } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }