#P3726. [AHOI2017/HNOI2017] 抛硬币

    ID: 1371 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2017各省省选安徽湖南O2优化枚举,暴力中国剩余定理,CRT逆元

[AHOI2017/HNOI2017] 抛硬币

Description

A and B are good friends who often play together. Recently, B has been addicted to a mobile gacha game, grinding every day and not studying at all. After several months, he has never drawn an SSR, which makes him doubt life. The diligent A wants to persuade B to quit the game and study, so he decides to use coin tossing to show B that he is thoroughly unlucky. They would toss coins at the same time; if the number of heads A gets is greater than the number of heads B gets, then A wins.

However, A was also once addicted to a gacha game and has never drawn a UR, so he is not confident in his luck. He decides to cheat by secretly tossing a few extra times; to avoid suspicion, he will not toss too many extra times. Let aa be the total number of times A tosses, and bb be the total number of times B tosses. In how many possible outcomes can A defeat B? Since the answer can be large, you only need to output the last kk digits in decimal.

Input Format

Multiple test cases. For each test case, input three integers a,b,ka, b, k, representing the number of times A tosses, the number of times B tosses, and how many digits of the final answer to keep.

Output Format

For each test case, output one number: the last kk digits of the answer. If it has fewer than kk digits, pad with leading zeros.

2 1 9
3 2 1
000000004
6

Hint

For the first test case, when A tosses 22 times and B tosses 11 time, there are 44 favorable outcomes in which A gets more heads than B. (01,0),(10,0),(11,0),(11,1)(01, 0), (10, 0), (11, 0), (11, 1).

For the second test case, when A tosses 33 times and B tosses 22 times, there are 1616 favorable outcomes in which A gets more heads than B. $(001, 00), (010, 00), (100, 00), (011, 00), (101, 00), (110, 00), (111, 00), (011, 01)$ $(101, 01), (110, 01), (111, 01), (011, 10), (101, 10), (110, 10), (111, 10), (111, 11)$.

Constraints

10%10\% of the testdata satisfies a,b20a, b \le 20.

30%30\% of the testdata satisfies a,b100a, b \le 100.

70%70\% of the testdata satisfies a,b105a, b \le 10^5, among which 20%20\% satisfies a=ba = b.

100%100\% of the testdata satisfies 1a,b10151 \le a, b \le 10^{15}, bab+104b \le a \le b + 10^4, 1k91 \le k \le 9, and the number of test cases is at most 1010.

Translated by ChatGPT 5