#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 argc, const char *argv[]) {
  int a;
  while (scanf("%d", &a) == 1) {
    int digits = 1;
    int remainder = 1 % a;
    while (remainder != 0) {
      remainder = (1 + 10 * remainder) % a;
      digits++;
    }
    printf("%d\n", digits);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec3(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    119c <main+0x7c>
movl   $0x1,-0x18(%rbp)
mov    $0x1,%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1188 <main+0x68>
imul   $0xa,-0x1c(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1162 <main+0x42>
mov    -0x18(%rbp),%esi
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
jmp    1136 <main+0x16>
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>
cmp    $0x1,%eax
jne    11b4 <main+0x94>
lea    0xebd(%rip),%r14
lea    0xeb3(%rip),%r15
lea    0xc(%rsp),%rbx
jmp    1178 <main+0x58>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11b4 <main+0x94>
mov    0xc(%rsp),%ecx
mov    $0x1,%esi
mov    $0x1,%eax
xor    %edx,%edx
idiv   %ecx
test   %edx,%edx
je     1160 <main+0x40>
mov    $0x1,%edx
mov    $0x1,%esi
nopl   0x0(%rax,%rax,1)
add    %edx,%edx
lea    (%rdx,%rdx,4),%eax
or     $0x1,%eax
add    $0x1,%esi
cltd
idiv   %ecx
test   %edx,%edx
jne    11a0 <main+0x80>
jmp    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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %9
9: ; preds = %26, %2
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %29
12: ; preds = %9
store i32 1, i32* %7
%13 = load i32, i32* %6
%14 = srem i32 1, %13
store i32 %14, i32* %8
br label %15
15: ; preds = %18, %12
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i32, i32* %8
%20 = mul nsw i32 10, %19
%21 = add nsw i32 1, %20
%22 = load i32, i32* %6
%23 = srem i32 %21, %22
store i32 %23, i32* %8
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %15
26: ; preds = %15
%27 = load i32, i32* %7
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %9
29: ; preds = %9
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(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %24
7: ; preds = %2, %19
%8 = load i32, i32* %3
%9 = srem i32 1, %8
%10 = icmp eq i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %7, %11
%12 = phi i32 [ %17, %11 ], [ 1, %7 ]
%13 = phi i32 [ %16, %11 ], [ 1, %7 ]
%14 = mul nsw i32 %12, 10
%15 = or i32 %14, 1
%16 = add nuw nsw i32 %13, 1
%17 = srem i32 %15, %8
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %11
19: ; preds = %11, %7
%20 = phi i32 [ 1, %7 ], [ %16, %11 ]
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%23 = icmp eq i32 %22, 1
br i1 %23, label %7, label %24
24: ; preds = %19, %2
ret i32 0
}