#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 main() {
  int n, s, rem;
  while (scanf("%d", &n) == 1) {
    rem = 0;
    s = 0;
    while (1) {
      rem = (rem * 10 + 1) % n;
      s++;
      if (rem == 0)
        break;
    }
    printf("%d\n", s);
  }
  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>
cmp    $0x1,%eax
jne    1195 <main+0x75>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
imul   $0xa,-0x10(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    117c <main+0x5c>
jmp    1181 <main+0x61>
jmp    1156 <main+0x36>
mov    -0xc(%rbp),%esi
lea    0xe78(%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>
cmp    $0x1,%eax
jne    119a <main+0x7a>
lea    0xebd(%rip),%r14
lea    0xeb3(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %esi,%esi
mov    0xc(%rsp),%ecx
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
add    %edx,%edx
lea    (%rdx,%rdx,4),%eax
or     $0x1,%eax
cltd
idiv   %ecx
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>
cmp    $0x1,%eax
je     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
store i32 0, i32* %1
br label %5
5: ; preds = %21, %0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %24
8: ; preds = %5
store i32 0, i32* %4
store i32 0, i32* %3
br label %9
9: ; preds = %8, %20
%10 = load i32, i32* %4
%11 = mul nsw i32 %10, 10
%12 = add nsw i32 %11, 1
%13 = load i32, i32* %2
%14 = srem i32 %12, %13
store i32 %14, i32* %4
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %9
br label %21
20: ; preds = %9
br label %9
21: ; preds = %19
%22 = load i32, i32* %3
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %5
24: ; preds = %5
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 i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp eq i32 %3, 1
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 [ %13, %7 ], [ 0, %5 ]
%9 = phi i32 [ %12, %7 ], [ 0, %5 ]
%10 = mul nsw i32 %9, 10
%11 = or i32 %10, 1
%12 = srem i32 %11, %6
%13 = add nuw nsw i32 %8, 1
%14 = icmp eq i32 %12, 0
br i1 %14, 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 %13)
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%18 = icmp eq i32 %17, 1
br i1 %18, label %5, label %19
19: ; preds = %15, %0
ret i32 0
}