#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 gcd(ull x, ull y) { while (y != 0) { ull t = x % y; x = y; y = t; } return x; } ull count_combinations(ull n, ull k) { ull r = 1; for(ull d = 1; d <= k; ++d, --n) { ull g = gcd(r, d); r /= g; ull t = n / (d / g); r = (r * t) % MODD; } return r; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; int M; cin >> N >> M; N /= 1000; N %= M; cout << count_combinations(M, N%M) << endl; return 0; }