A,B,C = map(int,input().split()) cnt=0 for i in range(1,A+1): cnt+=i**B print(cnt%C)