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