아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

K-transform

시간 제한2초메모리 제한256 MB

요약
k진법 함수 f를 정확히 m번 적용해 1이 되는 양의 정수 n의 개수를 소수 mod로 나눈 나머지를 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 조합론, 수학
정답자
아직 제출이 없습니다

문제

Let us fix an integer k≥2k \ge 2 and define a function ff: N→N\mathbb{N} \rightarrow \mathbb{N}:

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

If we take some integer n≥1n \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} (2≤k≤1042 \le k \le 10^{4}, 0≤m≤10180 \le m \le 10^{18}, 2≤mod<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.

예제2

  1. 예제 1

    입력
    2 4 31
    
    예상 출력
    5
    
  2. 예제 2

    입력
    3 13 59
    
    예상 출력
    36