#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 */
scalar_t__ EOF;
int /*<<< orphan*/ printf(char *, int);
scalar_t__ scanf(char *, int *);
int main() {
  int n;
  int ones, num_digits;
  while (scanf("%d\n", &n) != EOF) {
    num_digits = 1;
    ones = 1;
    while (n > ones) {
      ones = ones * 10 + 1;
      num_digits++;
    }
    while (ones % n != 0) {
      ones = (ones % n) * 10 + 1;
      num_digits++;
    }
    printf("%d\n", num_digits);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    0x2ea2(%rip),%rcx
cmp    (%rcx),%rax
je     11c8 <main+0xa8>
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1181 <main+0x61>
imul   $0xa,-0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115d <main+0x3d>
jmp    1186 <main+0x66>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
je     11b4 <main+0x94>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
imul   $0xa,%edx,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1186 <main+0x66>
mov    -0x10(%rbp),%esi
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x10,%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>
mov    0x2ea7(%rip),%r15
cmp    (%r15),%rax
jne    1152 <main+0x32>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xea7(%rip),%rbx
lea    0xc(%rsp),%r14
jmp    1178 <main+0x58>
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
cmp    (%r15),%rax
je     1146 <main+0x26>
mov    0xc(%rsp),%ecx
mov    $0x1,%eax
mov    $0x1,%esi
cmp    $0x2,%ecx
jl     11af <main+0x8f>
mov    $0x1,%esi
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
nop
add    %eax,%eax
lea    (%rax,%rax,4),%eax
or     $0x1,%eax
add    $0x1,%esi
cmp    %eax,%ecx
jg     11a0 <main+0x80>
nop
cltd
idiv   %ecx
test   %edx,%edx
je     1160 <main+0x40>
add    %edx,%edx
lea    (%rdx,%rdx,4),%eax
or     $0x1,%eax
add    $0x1,%esi
jmp    11b0 <main+0x90>

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

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