#include #define FORR(i,b,e) for(int i=(b);i<(int)(e);++i) #define FOR(i,e) FORR(i,0,e) #define dump(var) cerr << #var ": " << var << "\n" #define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n" typedef long long ll; typedef unsigned long long ull; const ull MODD = 1e9; using namespace std; ull pt[2][10100]; ull count_combinations_pascal(ull n, ull k) { fill(pt[0], pt[0]+10100, 0); fill(pt[1], pt[1]+10100, 0); pt[0][0] = pt[1][0] = 1; for (int i = 1; i <= n; ++i) { ull *ra = pt[(i-1)&1], *rb = pt[i&1]; for (int j = 1; j <= i + 1; ++j) { rb[j] = (ra[j-1] + ra[j]) % MODD; } } return pt[n&1][k]; } int main() { cin.tie(0); ios::sync_with_stdio(false); ull N, M; cin >> N >> M; N /= 1000; cout << count_combinations_pascal(M, N%M) << endl; return 0; }