# 11402번. 이항 계수 4
# 루카스 정리
# https://bowbowbow.tistory.com/2
importsyssys.setrecursionlimit(5000)# 안 써주면 터진다
defbinomial(n,k,p):ifcache[n][k]!=0:returncache[n][k]ifk==0orn==k:cache[n][k]=1returncache[n][k]cache[n][k]=(binomial(n-1,k-1,p)+binomial(n-1,k,p)%p)returncache[n][k]defget_digits(n,b):# b진법 전개식으로 나타내기
d=[]whilen:d.append(n%b)n//=breturnddeflucas_theorem(n,k,p):ret=1nd=get_digits(n,p)kd=get_digits(k,p)foriinrange(max(len(nd),len(kd))):nn,kk=0,0ifi<len(nd):nn=nd[i]else:nn=0ifi<len(kd):kk=kd[i]else:kk=0ifnn<kk:# 0으로 취급
return0ret=(ret*binomial(nn,kk,p)%p)# 계산
returnretn,k,m=map(int,input().split())cache=[[0for_inrange(2010)]for_inrange(2010)]print(lucas_theorem(n,k,m))"""
# 다른 풀이
from math import factorial
def nCr(n, r):
if r > n:
return 0
else:
return factorial(n)//factorial(r)//factorial(n-r) # nCr
n, k, m = map(int, input().split())
ans = 1
while n > 0:
ans = ans*nCr(n % m, k % m) % m
n //= m
k //= m
print(ans)
"""