K-transform

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

Let us fix an integer k2k \ge 2 and define a function ff: NN\mathbb{N} \rightarrow \mathbb{N}:

f(n)={ n/k, if kn   n1, otherwisef(n)= \begin{cases}  & n / k \text{, if } k \mid n  \\\  & n - 1 \text{, otherwise} \end{cases}

If we take some integer n1n \ge 1 and will apply function ff some (possibly 00) times then we will end up with 11. For example, if k=3k=3 then f(f(f(f(f(16)))))=f(f(f(f(15))))=f(f(f(5)))=f(f(4))=f(3)=1f(f(f(f(f(16)))))=f(f(f(f(15))))=f(f(f(5)))=f(f(4))=f(3)=1.

Your task is to calculate the amount of such nn that we will end up with 11 after exactly mm iterations. The answer may be very large, so you have to output it modulo mod\mathit{mod}.

입력

The first line contains three integers separated by spaces: kk, mm, mod\mathit{mod} (2k1042 \le k \le 10^{4}, 0m10180 \le m \le 10^{18}, 2mod<3002 \le \mathit{mod} < 300). It is guaranteed that mod\mathit{mod} is prime.

출력

Print one integer: the answer to the problem modulo mod\mathit{mod}.

힌트

N\mathbb{N} is the set of positive integers.