def modp(a,p,m):
if a==0:
return 0
ans=1;
while(p>0):
if p&1>0:
ans*=a
ans%=m
a*=a
a%=m
p>>=1
return ans
def Main():
try:
while True:
a=int(input())
p=int(input())
m=int(input())
print(modp(a,p,m))
a=input()
except EOFError:
return 0
if __name__=='__main__':
Main()
if a==0:
return 0
ans=1;
while(p>0):
if p&1>0:
ans*=a
ans%=m
a*=a
a%=m
p>>=1
return ans
def Main():
try:
while True:
a=int(input())
p=int(input())
m=int(input())
print(modp(a,p,m))
a=input()
except EOFError:
return 0
if __name__=='__main__':
Main()
Comments
Post a Comment