#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);
scalar_t__ scanf(char *, int *);
int main() {
  int input, divided, numOne, remainder;
  while (scanf("%d", &input) > 0) {
    divided = 1;
    numOne = 1;
    do {
      remainder = divided % input;
      if (remainder) {
        divided = remainder * 10 + 1;
        numOne++;
      }
    } while (remainder);
    printf("%d\n", numOne);
  }
  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
call   1040 <scanf@plt>
cmp    $0x0,%rax
jle    11a1 <main+0x81>
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117e <main+0x5e>
imul   $0xa,-0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1183 <main+0x63>
cmpl   $0x0,-0x14(%rbp)
jne    1157 <main+0x37>
mov    -0x10(%rbp),%esi
lea    0xe6c(%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   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xed0(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
test   %rax,%rax
jle    119b <main+0x7b>
lea    0xebd(%rip),%r14
lea    0xeb3(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%eax
xor    %esi,%esi
mov    0xc(%rsp),%ecx
nopl   0x0(%rax,%rax,1)
cltd
idiv   %ecx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
or     $0x1,%eax
add    $0x1,%esi
test   %edx,%edx
jne    1170 <main+0x50>
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
test   %rax,%rax
jg     1160 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%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
store i32 0, i32* %1
br label %6
6: ; preds = %26, %0
%7 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %6
store i32 1, i32* %3
store i32 1, i32* %4
br label %10
10: ; preds = %23, %9
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = srem i32 %11, %12
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %10
%17 = load i32, i32* %5
%18 = mul nsw i32 %17, 10
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %22
22: ; preds = %16, %10
br label %23
23: ; preds = %22
%24 = load i32, i32* %5
%25 = icmp ne i32 %24, 0
br i1 %25, label %10, label %26
26: ; preds = %23
%27 = load i32, i32* %4
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %6
29: ; preds = %6
ret i32 0
}

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