#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, long long);
int scanf(char *, long long *, long long *, long long *);
int main() {
  long long n, p, m;
  while (scanf("%lld %lld %lld", &n, &p, &m) == 3) {
    long long ans = 1;
    while (p > 0) {
      if (p % 2 == 1)
        ans = (ans * n);
      ans = ans % m;
      n = (n * n);
      n = n % m;
      p = p / 2;
    }
    printf("%lld\n", ans);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1040 <scanf@plt>
cmp    $0x3,%eax
jne    11dd <main+0xbd>
movq   $0x1,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    11c8 <main+0xa8>
mov    -0x18(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x1,%rdx
jne    1188 <main+0x68>
mov    -0x28(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
jmp    1158 <main+0x38>
mov    -0x28(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
lea    0x10(%rsp),%rcx
call   1040 <scanf@plt>
cmp    $0x3,%eax
jne    1220 <main+0x100>
mov    $0x1,%ebp
lea    0xea4(%rip),%r15
lea    0x8(%rsp),%r12
mov    %rsp,%r13
lea    0x10(%rsp),%r14
jmp    119f <main+0x7f>
nopl   0x0(%rax,%rax,1)
mov    %rcx,0x8(%rsp)
mov    %rax,(%rsp)
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1040 <scanf@plt>
cmp    $0x3,%eax
jne    1220 <main+0x100>
mov    (%rsp),%rdi
mov    $0x1,%esi
test   %rdi,%rdi
jle    1179 <main+0x59>
mov    0x8(%rsp),%rcx
mov    $0x1,%esi
mov    0x10(%rsp),%rbx
jmp    11da <main+0xba>
xchg   %ax,%ax
mov    %rcx,%rax
cqto
idiv   %rbx
mov    %rdx,%rcx
mov    %rdi,%rax
shr    %rax
cmp    $0x1,%rdi
mov    %rax,%rdi
jbe    1170 <main+0x50>
test   $0x1,%dil
mov    %rcx,%rax
cmove  %rbp,%rax
imul   %rsi,%rax
mov    %rax,%rdx
or     %rbx,%rdx
shr    $0x20,%rdx
je     1200 <main+0xe0>
cqto
idiv   %rbx
mov    %rdx,%rsi
jmp    1206 <main+0xe6>
nop
xor    %edx,%edx
div    %ebx
mov    %edx,%esi
imul   %rcx,%rcx
mov    %rcx,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    11c0 <main+0xa0>
mov    %ecx,%eax
xor    %edx,%edx
div    %ebx
mov    %edx,%ecx
jmp    11cb <main+0xab>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"%lld %lld %lld\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
br label %6
6: ; preds = %33, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64* %2, i64* %3, i64* %4)
%8 = icmp eq i32 %7, 3
br i1 %8, label %9, label %36
9: ; preds = %6
store i64 1, i64* %5
br label %10
10: ; preds = %21, %9
%11 = load i64, i64* %3
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %33
13: ; preds = %10
%14 = load i64, i64* %3
%15 = srem i64 %14, 2
%16 = icmp eq i64 %15, 1
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i64, i64* %5
%19 = load i64, i64* %2
%20 = mul nsw i64 %18, %19
store i64 %20, i64* %5
br label %21
21: ; preds = %17, %13
%22 = load i64, i64* %5
%23 = load i64, i64* %4
%24 = srem i64 %22, %23
store i64 %24, i64* %5
%25 = load i64, i64* %2
%26 = load i64, i64* %2
%27 = mul nsw i64 %25, %26
store i64 %27, i64* %2
%28 = load i64, i64* %2
%29 = load i64, i64* %4
%30 = srem i64 %28, %29
store i64 %30, i64* %2
%31 = load i64, i64* %3
%32 = sdiv i64 %31, 2
store i64 %32, i64* %3
br label %10
33: ; preds = %10
%34 = load i64, i64* %5
%35 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %34)
br label %6
36: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"%lld %lld %lld\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i64* %1 to i8*
%5 = bitcast i64* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = call i32 @scanf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64* %1, i64* %2, i64* %3)
%8 = icmp eq i32 %7, 3
br i1 %8, label %9, label %34
9: ; preds = %0, %29
%10 = load i64, i64* %2
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %9
%13 = load i64, i64* %1
%14 = load i64, i64* %3
br label %15
15: ; preds = %12, %15
%16 = phi i64 [ 1, %12 ], [ %23, %15 ]
%17 = phi i64 [ %10, %12 ], [ %26, %15 ]
%18 = phi i64 [ %13, %12 ], [ %25, %15 ]
%19 = and i64 %17, 1
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i64 1, i64 %18
%22 = mul nsw i64 %21, %16
%23 = srem i64 %22, %14
%24 = mul nsw i64 %18, %18
%25 = srem i64 %24, %14
%26 = lshr i64 %17, 1
%27 = icmp ult i64 %17, 2
br i1 %27, label %28, label %15
28: ; preds = %15
store i64 %25, i64* %1
store i64 %26, i64* %2
br label %29
29: ; preds = %28, %9
%30 = phi i64 [ %23, %28 ], [ 1, %9 ]
%31 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %30)
%32 = call i32 @scanf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64* %1, i64* %2, i64* %3)
%33 = icmp eq i32 %32, 3
br i1 %33, label %9, label %34
34: ; preds = %29, %0
ret i32 0
}