luogu#P5224. Candies

Candies

Background

JerryC has a big bag of candies, and he is eating this bag at a speed of 1 t/ms1\ \textrm{t/ms}.

Problem Description

JerryC has NN boxes of candies (all different from each other). At first, he wanted to pick MM boxes, but he felt it was not enough, so he wants to take some more. Since he likes the number KK, as long as the number of boxes he takes out xx (xMx \ge M) satisfies xM(modK)x \equiv M\pmod{K}, JerryC will feel satisfied.

Find how many ways can make JerryC feel satisfied. Output the number of ways mod 1004535809\bmod\ 1004535809.

Input Format

One line with three non-negative integers N,M,KN, M, K.

Output Format

One line with one non-negative integer, the number of ways mod 1004535809\bmod\ 1004535809.

10 2 3

342

Hint

Sample explanation:

He can take out 22 boxes, 55 boxes, or 88 boxes. Just compute the combinations:

(102)+(105)+(108)=342\binom{10}{2}+\binom{10}{5}+\binom{10}{8}=342

Constraints:

Test Point ID NN\le KK\le
11
232-3 10610^6 1010
484-8 101210^{12} 100100
9129-12 101510^{15} 10310^3
122012-20 101810^{18} 10410^4

0M<K0 \leq M < K

Translated by ChatGPT 5