#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 */
long long pow(long long, long long);
int /*<<< orphan*/ printf(char *, long long);
int scanf(char *, long long *, ...);
long long sqrt(long long);
int main() {
  long long p, q, n, total, pp, a, b;
  while (scanf("%lld %lld", &p, &q) == 2) {
    if (p == 0 && q == 0)
      break;
    scanf("%lld", &n);
    pp = sqrt(p * p - 4 * q);
    a = (p + pp) / 2;
    b = p - a;
    total = pow(a, n) + pow(b, n);
    printf("%lld\n", total);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
cmp    $0x2,%eax
jne    121b <main+0xdb>
cmpq   $0x0,-0x10(%rbp)
jne    1189 <main+0x49>
cmpq   $0x0,-0x18(%rbp)
jne    1189 <main+0x49>
jmp    121b <main+0xdb>
lea    0xe75(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rdi
imul   -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
sub    %rax,%rdi
call   1060 <sqrt@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
add    -0x30(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
sub    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <pow@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <pow@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xdf9(%rip),%rdi
call   1030 <printf@plt>
jmp    114f <main+0xf>
xor    %eax,%eax
add    $0x50,%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    0xeab(%rip),%rdi
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x2,%eax
jne    1223 <main+0xe3>
lea    0xe96(%rip),%r12
lea    0xe85(%rip),%r13
mov    %rsp,%rbx
lea    0x8(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rsp),%rax
or     0x8(%rsp),%rax
je     1223 <main+0xe3>
lea    0xe5f(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    (%rsp),%rdi
imul   %rdi,%rdi
mov    0x8(%rsp),%rax
shl    $0x2,%rax
sub    %rax,%rdi
call   1060 <sqrt@plt>
mov    (%rsp),%r14
add    %r14,%rax
mov    %rax,%rdi
shr    $0x3f,%rdi
add    %rax,%rdi
sar    %rdi
sub    %rdi,%r14
mov    0x10(%rsp),%rsi
call   1050 <pow@plt>
mov    %rax,%r15
mov    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1050 <pow@plt>
add    %rax,%r15
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x2,%eax
je     1190 <main+0x50>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%lld %lld\00"
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [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
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
br label %9
9: ; preds = %19, %0
%10 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64* %2, i64* %3)
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %44
12: ; preds = %9
%13 = load i64, i64* %2
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i64, i64* %3
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
br label %44
19: ; preds = %15, %12
%20 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %4)
%21 = load i64, i64* %2
%22 = load i64, i64* %2
%23 = mul nsw i64 %21, %22
%24 = load i64, i64* %3
%25 = mul nsw i64 4, %24
%26 = sub nsw i64 %23, %25
%27 = call i64 @sqrt(i64 %26)
store i64 %27, i64* %6
%28 = load i64, i64* %2
%29 = load i64, i64* %6
%30 = add nsw i64 %28, %29
%31 = sdiv i64 %30, 2
store i64 %31, i64* %7
%32 = load i64, i64* %2
%33 = load i64, i64* %7
%34 = sub nsw i64 %32, %33
store i64 %34, i64* %8
%35 = load i64, i64* %7
%36 = load i64, i64* %4
%37 = call i64 @pow(i64 %35, i64 %36)
%38 = load i64, i64* %8
%39 = load i64, i64* %4
%40 = call i64 @pow(i64 %38, i64 %39)
%41 = add nsw i64 %37, %40
store i64 %41, i64* %5
%42 = load i64, i64* %5
%43 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %42)
br label %9
44: ; preds = %18, %9
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"%lld %lld\00"
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [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 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64* %1, i64* %2)
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %35
9: ; preds = %0, %15
%10 = load i64, i64* %1
%11 = icmp eq i64 %10, 0
%12 = load i64, i64* %2
%13 = icmp eq i64 %12, 0
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %35, label %15
15: ; preds = %9
%16 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%17 = load i64, i64* %1
%18 = mul nsw i64 %17, %17
%19 = load i64, i64* %2
%20 = mul i64 %19, -4
%21 = add i64 %20, %18
%22 = call i64 @sqrt(i64 %21)
%23 = load i64, i64* %1
%24 = add nsw i64 %23, %22
%25 = sdiv i64 %24, 2
%26 = sub nsw i64 %23, %25
%27 = load i64, i64* %3
%28 = call i64 @pow(i64 %25, i64 %27)
%29 = load i64, i64* %3
%30 = call i64 @pow(i64 %26, i64 %29)
%31 = add nsw i64 %30, %28
%32 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %31)
%33 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64* %1, i64* %2)
%34 = icmp eq i32 %33, 2
br i1 %34, label %9, label %35
35: ; preds = %15, %9, %0
ret i32 0
}