問題一覧 > 通常問題

No.129 New Year's Money (2)

レベル : / AI推定難易度 : 800 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 254
作問者 : yuki2006
お気に入りにしたユーザー ProblemId : 143 / 自分の提出
問題文最終更新日: 2026-06-25 14:36:25
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 77 (順位表) の他の問題:

Problem Statement

Yasuo has a budget of only $N$ yen, but he wants to give New Year's money to $M$ children of his relatives.
He wants to put only $1000$-yen bills in the envelopes, and he wants to give amounts that are as equal as possible and as large as possible.

This time, unlike last time, he has decided to also hand out the budget left over after distribution, as "winning prizes".

As preparation, after putting an equal and maximum amount of $1000$-yen bills into every New Year's money envelope, if any budget remains, then as "winning prizes",
he will randomly distribute the additional bills among the envelopes, where each single envelope either receives $1000$ yen or does not.

Here, assuming that it is not known who will receive which envelope,
find the number of combinations of the amounts of New Year's money that the $M$ people can each receive.
All of the remainder is to be used as long as it can be made into 1000-yen bills.
Since the answer can be very large, find it modulo $1000000000=10^9$ (note that this is not a prime).

Input

N
M

All inputs are given as integers.
$1\le N \le 10000000000000000=10^{16}$
$1\le M \le 10000=10^{4}$

Output

Output the number of combinations of the amounts of New Year's money, modulo $1000000000=10^9$.
Print a newline at the end.

Sample

Sample 1
Input
10000
5
Output
1

The budget is $10000$ yen and it is distributed to $5$ people, so everyone equally gets $2000$ yen per $1$ person.
(That is, 1 way.)

Sample 2
Input
24500
9
Output
84

After distributing $1000$-yen bills equally, $6500$ yen remains, but only $6000$ yen of the remainder can be made into $1000$-yen bills.
The remainder is distributed randomly.
Then there are $84$ ways to distribute it.

Sample 3
Input
1800
6
Output
6

One of the $6$ people gets $1000$ yen.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。