a,b,c=map(int,input().split()) ans=0 if a<=c: for i in range(1,a+1): ans+=pow(i,b,c) ans%=c else: for i in range(1,a+1): if i>c: i%=c ans+=pow(i,b,c) ans%=c print(ans)