#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 *, int);
int scanf(char *, int *, int *, int *);
int main() {
  int base, c, b;
  int a;
  int i;
  int carry;
  while (scanf("%d%d%d", &base, &c, &b) == 3) {
    a = c;
    carry = 0;
    for (i = 0; 1; ++i) {
      int t = (a * b + carry);
      carry = t / base;
      a = t % base;
      if (carry == 0 && a == c)
        break;
    }
    printf("%d\n", i + 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1040 <scanf@plt>
cmp    $0x3,%eax
jne    11d9 <main+0xb9>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    1173 <main+0x53>
jmp    11c2 <main+0xa2>
mov    -0x14(%rbp),%eax
imul   -0x10(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11af <main+0x8f>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11af <main+0x8f>
jmp    11c2 <main+0xa2>
jmp    11b4 <main+0x94>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1164 <main+0x44>
mov    -0x18(%rbp),%esi
add    $0x1,%esi
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x20,%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    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1040 <scanf@plt>
cmp    $0x3,%eax
jne    11c9 <main+0xa9>
lea    0xeab(%rip),%r15
lea    0x14(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%ebx
xor    %esi,%esi
mov    0x14(%rsp),%ebp
mov    %edi,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
imul   %ebx,%eax
add    %ecx,%eax
cltd
idiv   %ebp
add    $0x1,%esi
mov    %eax,%ecx
mov    %edx,%eax
test   %ecx,%ecx
jne    1190 <main+0x70>
cmp    %edi,%eax
jne    1190 <main+0x70>
lea    0xe59(%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
je     1170 <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 = [7 x i8] c"%d%d%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
br label %9
9: ; preds = %38, %0
%10 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%11 = icmp eq i32 %10, 3
br i1 %11, label %12, label %42
12: ; preds = %9
%13 = load i32, i32* %3
store i32 %13, i32* %5
store i32 0, i32* %7
store i32 0, i32* %6
br label %14
14: ; preds = %35, %12
br i1 true, label %15, label %38
15: ; preds = %14
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = mul nsw i32 %16, %17
%19 = load i32, i32* %7
%20 = add nsw i32 %18, %19
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = load i32, i32* %2
%23 = sdiv i32 %21, %22
store i32 %23, i32* %7
%24 = load i32, i32* %8
%25 = load i32, i32* %2
%26 = srem i32 %24, %25
store i32 %26, i32* %5
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %15
%30 = load i32, i32* %5
%31 = load i32, i32* %3
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
br label %38
34: ; preds = %29, %15
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %14
38: ; preds = %33, %14
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
br label %9
42: ; preds = %9
ret i32 0
}

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