'''No.2007 Arbitrary Mod (Easy) ''' a, n, M = map(int, input().split()) def remainder(): if M != 0: return a ** n % M if M == 0: return None