package main import ( "bufio" "fmt" "math" "os" "strconv" ) var sc = bufio.NewScanner(os.Stdin) var rdr = bufio.NewReaderSize(os.Stdin, 1000000) func main() { sc.Split(bufio.ScanWords) n, m := nextInt(), nextInt() mod := (n/1000 - n/(1000*m)*m) fmt.Println(ncr(uint64(m), uint64(mod), 1000000000)) } func ncr(n, r, mod uint64) uint64 { if n < 0 || r < 0 || r > n { return 0 } if r > n/2 { r = n - r } a := make([]uint64, n) for i := range a { a[i] = n - uint64(i) } ps := eratosthenes(int(r)) for _, p := range ps { for q := uint64(p); q <= r; q *= uint64(p) { m := n % q for i, j := m, uint64(0); j < r/q; i, j = i+q, j+1 { a[i] /= uint64(p) } } } mul := uint64(1) for i := uint64(0); i < r; i++ { mul = mul * a[i] % mod } return mul } func nextLine() string { sc.Scan() return sc.Text() } func nextInt() int { i, _ := strconv.Atoi(nextLine()) return i } func eratosthenes(n int) []int { if n < 2 { return []int{} } r := int(math.Floor(math.Sqrt(float64(n)))) list := make([]bool, n+1) list[0], list[1] = true, true for i := 2; i <= r; i++ { if !list[i] { for j := i * i; j <= n; j += i { list[j] = true } } } l := n / int(math.Ceil(math.Log(float64(n)))) primes := make([]int, 0, l) for i, v := range list { if v { continue } primes = append(primes, i) } return primes }