#include using namespace std; using ll = long long; #define BEGIN_STACK_EXTEND(size) \ void *stack_extend_memory_ = malloc(size); \ void *stack_extend_origin_memory_; \ char *stack_extend_dummy_memory_ = (char *)alloca((1 + (int)(((long long)stack_extend_memory_) & 127)) * 16); \ *stack_extend_dummy_memory_ = 0; \ asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp" \ : "=b"(stack_extend_origin_memory_) \ : "a"((char *)stack_extend_memory_ + (size)-1024)); #define END_STACK_EXTEND \ asm volatile("mov %%rax, %%rsp" ::"a"(stack_extend_origin_memory_)); \ free(stack_extend_memory_); #define mod 1000000007ll #define loop(i, n) for (int i = 0; i < n; i++) #define flagcount(bit) __builtin_popcount(bit) #define flag(x) (1ll << x) #define flagadd(bit, x) bit |= flag(x) #define flagpop(bit, x) bit &= ~flag(x) #define flagon(bit, i) bit &flag(i) #define flagoff(bit, i) !(bit & (1ll << i)) #define all(v) v.begin(), v.end() #define putout(a) cout << a << '\n' #define Sum(v) accumulate(all(v), 0ll) template bool chmax(T &a, const T &b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } void AS(ll X, ll L, ll R) { assert(L <= X && X <= R); } ll fib[300000]; int main() { // cout << fixed << setprecision(10); /* A0=1 A1=A0=1 Ai=A_{max(0,i-L)}+...+A_{i-1} A_L=A_0+....+A_{L-1} よって、区間和で解ける */ ll N, L; cin >> N >> L; fib[0] = 1; ll now = 1; loop(i, 280000) { if ((i + 1) > L) { now -= fib[(i + 1) - L - 1]; now += mod; now %= mod; } fib[i + 1] = now % mod; now += fib[i + 1]; now %= mod; } putout(fib[N]); return 0; }