#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef vector vi; typedef vector vvi; typedef pair pii; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(ll i=a; iDUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this< ostream& operator<<(ostream& os, vector const& v){ rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" "); return os; } ll mod = 1000000000; ll N,M; int main(){ while(cin>>N>>M){ N/=1000; ll rem = N - N/M * M; vi x = {1,1}; rep(i,M-1){ vi y(x.size()+1); y[0] = 1; rep(i,x.size()-1){ y[i+1] = (x[i+1]+x[i])%mod; } y.back() = y[0]; dump(y); swap(x,y); } cout << x[rem] << endl; // cout << nCr(M,rem) << endl; } }