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