#include #include #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; const int N = 10010; int a[N]; int main(void){ ll n,m; cin >> n >> m; n /= 1000; n %= m; // C(m, n) REP(i, 0, n) { a[i] = m - i; } for (int i = n; i >= 2; --i) { int j; for (j = n - 1; j >= 0; --j){ if (a[j] % i == 0) { a[j] /= i; break; } } if (j == -1) { assert(! "not found"); } } ll sum = 1; const ll mod = 1e9; REP(i, 0, n) { sum *= a[i]; sum %= mod; } cout << sum << endl; }