Screen Shot 2018-01-08 at 10.23.43 AM.png

#include <stdio.h>
int fib(int n,int k){
	long long int i,tot = 0;
	long long f[n+1];
	f[0] = 0;
	if(n<=k){
		return 1;
	}else if(n>k){
		for(i=1;i<=k;i++){
			f[i]=1;
		}
		f[k+1]=k;
		//printf("%lld\n",f[k+1]);
		tot = k;
		for(i=k+2;i<=n;i++){
			tot = tot + f[i-1] - f[i-k-1];
            tot%=1000000007;
            tot+=1000000007;
            tot%=1000000007;
			f[i] = tot;
			//printf("%lld %lld\n",f[i],f[i-k-1]);
		}	
	}
	return f[n];
}
int main() {
	long long int j,m,l;
	scanf("%lld %lld", &j, &m);
	l = fib(j,m);
	printf("%lld", (l%1000000007));
	return 0;
}